echo 1> / proc / sys / net / ipv4 / ip_forward
ipset -N good iphash
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -t nat -A PREROUTING -m set! --set good src -j DNAT --to 192.168.88.1
conntrack -F
conntrack –F
we can manipulate the permissions of IP addresses to go to the Internet.mknod pipename p
$symbols
array specifies which characters from the hash will be used as a password. I use six characters, you can use any number greater than zero.debug
command sent to the pipe results in the output of the current IP address table with the access validity time to the debug
file. Example: echo debug >pipe
update
, and at midnight reload
<HTML> <FORM method="get" action=gen.php> <input name="PwdType" type="radio" value="Common" checked>Common Password</INPUT> <input name="PwdType" type="radio" value="CommonTill">Common Password till <select name="Till"> <option value=__8">8:00</option> ... <option value=__23">23:00</option> </select> </INPUT> <input name="PwdType" type="radio" value="Personal">Personal Password</INPUT> <select name="PersonalTill"> <option value=__8">8:00</option> ... <option value=__23">23:00</option> </SELECT> Client ID:<input name="ClientID" value=0> <INPUT type=submit value="Generate password"> </FORM> </HTML>
<? $Secret="123"; //Common secret $d=date("Ymd"); //Current Date $symbols=array(0,4,5,8,1,30); //Symbols in md5 hash for password. Numbers must be in 0..31 $ipnet="192.168.88."; if ( $PwdType == "Common" ) { $str=$d."-".$Secret; $r=md5($str); $res="*"; foreach ($symbols as &$i) {$res=$res.substr($r,$i,1);}; }; if ( $PwdType == "CommonTill" ) { $Till=utf8_decode($Till); $Till=substr($Till,1,strlen($Till)-2); $str=$d."-".$Till."-".$Secret; $r=md5($str); $res="#".$Till."-"; foreach ($symbols as &$i) {$res=$res.substr($r,$i,1);}; }; if ( $PwdType == "Personal" ) { $ip=$ipnet.$ClientID; $PersonalTill=utf8_decode($PersonalTill); $PersonalTill=substr($PersonalTill,1,strlen($PersonalTill)-2); $str=$d."-".$PersonalTill."-".$ip."-".$Secret; $r=md5($str); $res="$".$PersonalTill."-"; foreach ($symbols as &$i) {$res=$res.substr($r,$i,1);}; }; ?> <H2>Password="<?print $res;?>"</H2> <H1 align=center><a href="index.php">Return</a></H1>
<HTML> <!--0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF--> <? $addr="192.168.88.1"; $a=getenv("REMOTE_ADDR"); $s=getenv("SERVER_NAME"); $ipnet="192.168.88."; $p=strpos($a,$ipnet); if ($p === false) { print "<B>Internal error: <I>Wrong network (Network=$ipnet, Address=$a)</I></B> \n"; exit; }; if ($p > 0 ) { print "<B>Internal error: <I>Wrong network (Position=$p)</I></B> \n"; exit; }; ?> Please, call XXXX to get password. Your ID is <STRONG><? print substr($a,strlen($ipnet));?></STRONG> <FORM action=http://<?print $addr;?>/do.php method=post> <CENTER> Password <INPUT name=pwd type=password> <INPUT type=submit value="Activate Internet"> </CENTER> </FORM> </HTML>
<? $Secret="123"; //Common secret $d=date("Ymd"); //Current Date $symbols=array(0,4,5,8,1,30); //Symbols in md5 hash for password. Numbers must be in 0..31 $ipnet="192.168.88."; $ip=getenv("REMOTE_ADDR"); $pwd=$_POST["pwd"]; $fc=substr($pwd,0,1); //first charter is code of password type $PipeFile="./pipe"; if ($pwd == "") { print "<H1 align=center>Wrong empty password. <a href='/'>return</a></H1>"; exit; }; if ( $fc == "*" ) { $str=$d."-".$Secret; $r=md5($str); $res="*"; foreach ($symbols as &$i) {$res=$res.substr($r,$i,1);}; $Till=25; }; if ( $fc == "#" ) { $p=strpos($pwd,"-"); $Till=substr($pwd,1,$p-1); $str=$d."-".$Till."-".$Secret; $r=md5($str); $res="#".$Till."-"; foreach ($symbols as &$i) {$res=$res.substr($r,$i,1);}; }; if ( $fc == "$" ) { $p=strpos($pwd,"-"); $PersonalTill=substr($pwd,1,$p-1); $str=$d."-".$PersonalTill."-".$ip."-".$Secret; $r=md5($str); $res="$".$PersonalTill."-"; foreach ($symbols as &$i) {$res=$res.substr($r,$i,1);}; $Till=$PersonalTill; }; if ($pwd != $res) { print "<H1 align=center>Wrong password. <a href='/'>return</a></H1>"; exit; }; file_put_contents ( $PipeFile, substr($ip,strlen($ipnet))." $Till\n", FILE_APPEND); ?> <H1 align=center>Access to Internte granted</H1>
#!/bin/bash PipeFile="/var/www/html/pipe" LogFile="/var/log/script.log" ErrFile="/var/log/script.err" DebugFile="/var/log/script.debug" ipnet="192.168.88." ipset_prog="/usr/sbin/ipset" ipset_setname="good" ctr_prog="/usr/sbin/conntrack" function debug() { local d=`date` echo "$d Debuging started" >>$DebugFile for i in `seq 1 254`; do if [ ${b[$i]} != "0" ]; then echo "b[$i] = ${b[$i]}" >>$DebugFile fi done; echo "==================== Debuging finised =================" >>$DebugFile } function initfunc() { #Init for i in `seq 1 254`; do b[$i]="0" done; ( d=`date` echo "$d Init function called" $ipset_prog -F $ipsetname $ctr_prog -F ) &>>$LogFile }; function update() { ( local d1=`date` local d=`date +%H` echo "$d1 Update function called" for i in `seq 1 254`; do if [ ${b[$i]} -gt "0" ] && [ ${b[$i]} -le "$d" ]; then b[$i]=0 ip2="$ipnet$i" echo "Deleting address $ip2" &>>$LogFile $ipset_prog -D $ipset_setname $ip2 &>>$LogFile $ctr_prog -F fi done ) &>>$LogFile } #update ################# Start program ################# initfunc while true; do while read line; do a=( $line ) ip=${a[0]} tm=${a[1]} if [ "$ip" == "reload" ]; then initfunc continue fi if [ "$ip" == "update" ]; then update continue fi if [ "$ip" == "debug" ]; then debug continue fi b[$ip]=$tm ip2="$ipnet$ip" ( d=`date` echo "$d Added address $ip2 with time:$tm" $ipset_prog -A $ipset_setname $ip2 &>>$LogFile $ctr_prog -F ) &>>$LogFile update done <$PipeFile done
Source: https://habr.com/ru/post/163967/
All Articles