Public paste
Undefined
By: Guest | Date: Oct 18 2022 15:36 | Format: TCL/iTCL | Expires: never | Size: 9.35 KB | Hits: 37

  1. ;
  2. ; Portscanner v1.0 w/ IPv6 Support
  3. ; Everything works so far ;)
  4. ;
  5. ; Syntax:
  6. ;   /portscan [hostname/ip]
  7. ;
  8. ; Update:
  9. ;  - fixed hostnames with multiple IP adresses, using a random IP from the list now
  10.  
  11. ; -------------
  12. ; Dialog
  13. ; -------------
  14. dialog ps {
  15.   title "Portscanner"
  16.   size -1 -1 180 175
  17.   option dbu
  18.   icon $windir(system32\shell32.dll), 22
  19.   list 1, 5 65 170 100, size vsbar hsbar
  20.   edit "", 2, 24 4 150 10
  21.   text "Scan", 3, 5 5 16 8
  22.   edit "", 4, 30 25 35 10, limit 5
  23.   text "Start", 5, 8 25 16 8
  24.   text "End", 6, 8 35 16 8
  25.   box "Portrange", 7, 5 15 65 33
  26.   edit "", 8, 30 35 35 10, limit 5
  27.   box "Settings", 9, 75 15 100 33
  28.   combo 10, 80 25 35 50, size drop
  29.   combo 11, 80 35 35 50, size drop
  30.   check "T&imes", 20, 130 25 30 10
  31.   check "&Verbose", 21, 130 35 30 10
  32.   button "?", 17, 117 25 10 10, center
  33.   button "?", 18, 117 35 10 10, center
  34.   button "?", 22, 162 25 10 10, center
  35.   button "?", 24, 162 35 10 10, center
  36.   button "&Scan", 12, 4 50 33 12,default
  37.   button "&Reset", 13, 39 50 33 12
  38.   button "&Clear", 14, 74 50 33 12
  39.   button "S&ave", 16, 109 50 33 12
  40.   button "C&lose", 15, 144 50 33 12, cancel
  41.   text "", 19, 5 167 170 8
  42. }
  43. ; -------------
  44. ; Dialog Events
  45. ; -------------
  46. on *:dialog:ps:init:0:{
  47.   var %x = 10
  48.   while (%x < 10001) { did -a $dname 10 %x $+ ms | inc %x 10 }
  49.   %x = 0
  50.   while (%x < 100) { inc %x | did -a $dname 11 %x }
  51.   reset
  52. }
  53. on *:dialog:ps:sclick:*:{
  54.   if ($did = 12) { execute }
  55.   if ($did = 13) { reset }
  56.   if ($did = 14) { reset -l }
  57.   if ($did = 15) { .sockclose ps_* | .timerpScan off | unset %currentPort }
  58.   if ($did = 16) { save }
  59.   if ($did = 17) { _help ms }
  60.   if ($did = 18) { _help sc }
  61.   if ($did = 22) { _help ti }
  62.   if ($did = 24) { _help vb }
  63. }
  64. ; -------------
  65. ; Aliases
  66. ; -------------
  67. alias portscan {
  68.   if (!$dialog(ps)) { dialog -dm ps ps }
  69.   else { dialog -v ps }
  70.   if (!$busy) { if ($1) { did -fra ps 2 $1 } }
  71.   elseif ($1) { _help bs }
  72. }
  73. alias -l execute {
  74.   did -ra ps 2 $gettok($did(ps,2),1,32)
  75.   did -b ps 12
  76.   var %resolve = $nslookup($did(ps,2)).go
  77.   if ($did(ps,2)) {
  78.     if ($isip($did(ps,2)) || $busy || %resolve) {
  79.       if ($did(ps,4) <= $did(ps,8) && $did(ps,4) isnum 1-65535 && $did(ps,8) isnum 1-65535) {
  80.         if ($did(ps,12).text == &Scan) {
  81.           set %currentPort $did(ps,4) | sockclose ps_* | did -b ps 2,4,8,10,11,13,20,21
  82.           did -ra ps 12 &Stop | status | add 0 Scan started $iif($did(ps,21).state,using verbose)
  83.           if (%resolve) { add 0 Resolved: $v1 }
  84.           if ($numtok(%resolve,44) > 1) { %resolve = $gettok(%resolve,$r(1,$numtok(%resolve,44)),44) | add 0 Using first IP: %resolve }
  85.           .timerpScan -imo 0 $left($did(ps,10).seltext,-2) port.scanner.loop                
  86.         }
  87.         else {
  88.           did -ra ps 12 &Scan
  89.           if (%currentPort < $did(ps,8)) {
  90.             if ($input(Apply port %currentPort as new start port?,yau,Just Pause?)) {
  91.             did -ra ps 4 %currentPort | add 0 Scan paused at port $calc(%currentPort -1) }
  92.             else { add 0 Scan stopped at port $calc(%currentPort -1) }
  93.           }
  94.           status | did -e ps 2,4,8,10,11,13,20,21 | unset %currentPort
  95.         }
  96.       }
  97.       else { _help no }
  98.     }
  99.     else { _help ip }
  100.   }
  101.   else { _help ho }
  102.   did -e ps 12
  103. }
  104. alias -l save {
  105.   var %path = $$sfile(portscan- $+ $did(ps,2) $+ - $+ $replace($date $+ - $+ $time,/,-,:,-) $+ .log,Save log file,Save)
  106.   savebuf -o ps 1 $shortfn($nofile(%path)) $+ \ $+ $nopath(%path)
  107. }
  108. alias port.scanner.loop {
  109.   var %count = $sock(ps_*,0)
  110.   var %x = %count
  111.   while (%x) {
  112.     var %port = $gettok($sock(ps_*,%x),2,95)
  113.     if ($sock(ps_*,%x).mark) {
  114.       if ($calc($ticks - $ifmatch) > 300000) { sockclose $sock(ps_*,%x) | add %port Internal timeout limit of 5 minutes reached. }
  115.     }
  116.     dec %x
  117.   }
  118.   if (%currentPort < $calc($did(ps,8) +1)) {
  119.     if ((%count < $did(ps,11).seltext) && ($did(ps,12) != &Scan)) {
  120.       sockopen ps_ $+ %currentPort $did(ps,2) %currentPort
  121.       inc %currentPort
  122.     }
  123.   }
  124.   %count = $sock(ps_*,0)
  125.   if (!%count) {
  126.     .timerpScan off
  127.     if ($did(ps,12) != &Scan) { execute }
  128.   }
  129.   status $iif(%currentPort,$v1,0) %count
  130. }
  131. alias -l status {
  132.   did -ra ps 19 Next Port: $iif($1 isnum 0-65535,$1,0) Open Ports: $iif($2,$2,0)
  133. }
  134. alias -l isip {
  135.   var %re = /^\s*((?=.*::.*)(::)?([0-9A-F]{1,4}(:(?=[0-9A-F])|(?!\2)(?!\5)(::)|\z)){0,7}|((?=.*::.*)(::)?([0-9A-F]{1,4}(:(?=[0-9A-F])|(?!\7)(?!\10)(::))){0,5}|([0-9A-F]{1,4}:){6})((25[0-5]|(2[0-4]|1[0-9]|[1-9]?)[0-9])(\.(?=.)|\z)){4}|([0-9A-F]{1,4}:){7}[0-9A-F]{1,4})\s*$/i
  136.   if ($len($1)) {
  137.     if ($regex($1,%re) && $regml(1) == $1) { return $true }
  138.     return $iif($longip($longip($1)) == $1,$true,$false)
  139.   }
  140.   return $false
  141. }
  142. alias -l busy {
  143.   if ($did(ps,12).text == &Stop) { return $true }
  144.   return $false
  145. }
  146. alias -l _help {
  147.   if ($1 = vb) noop $input(It shows all connection tries. $crlf $crlf $+ Produces high CPU load. Use it only with timers of 100ms or above.,adiou,Help)
  148.   if ($1 = ms) noop $input(Time in milliseconds between each socket will be opened. $crlf $crlf $+ (Up to 10 Seconds.),adiou,Help)
  149.   if ($1 = sc) noop $input(Maximum amount of open connections at once.,adiou,Help)
  150.   if ($1 = bs) noop $input(Sorry $+ $chr(44) but the portscanner seems to be busy.,adwou,Error)
  151.   if ($1 = no) noop $input(Please check the portrange.,adwou,Error)
  152.   if ($1 = ho) noop $input(Please check the hostname.,adwou,Error)
  153.   if ($1 = ip) noop $input(Please use only IPv4/IPv6 masks that can be resolved.,adwou,Error)
  154.   if ($1 = ti) noop $input(Adds a timestamp to the output.,adiou,Help)
  155. }
  156. alias -l reset {
  157.   if ($1 != -l) {
  158.     did -c ps 10 2
  159.     did -c ps 11 20
  160.     did -f ps 2
  161.     did -ra ps 4 1
  162.     did -ra ps 8 65535
  163.     did -c ps 20
  164.     did -u ps 21
  165.     add 0 Portscan ready.
  166.     .sockclose ps_*
  167.     .timerpScan off
  168.     unset %currentPort
  169.     status
  170.   }
  171.   else {
  172.     did -r ps 1
  173.     add 0 List cleared.
  174.   }
  175. }
  176. alias -l add {
  177.   if ($dialog(ps)) {
  178.     did -a ps 1 $iif($did(ps,20).state,$time) $base($1,10,10,5) $+ $iif($prot($1),/ $+ $v1) : $+ $2-
  179.     did -c ps 1 $did(ps,1).lines
  180.     did -z ps 1
  181.   }
  182. }
  183. alias -l prot {
  184.   return $gettok($read($windir(system32\drivers\etc\services),nw,* $1 $+ /tcp*),1,32)
  185. }
  186.  
  187. alias -l windir {
  188.   .comopen windir WScript.Shell
  189.   if ($comerr) { !return }
  190.   var %a = $com(windir,ExpandEnvironmentStrings,3,bstr,% $+ windir%)
  191.   %a = $com(windir).result
  192.   .comclose windir
  193.   return %a $+ \ $+ $iif($1,$1-)
  194. }
  195. ; -------------
  196. ; Socket Events
  197. ; -------------
  198. on *:sockopen:ps_*:{
  199.   if ($dialog(ps)) {
  200.     var %port = $gettok($sockname,2,95)
  201.     if ($sock($sockname).status == active) { add %port Connected | sockmark $sockname $ticks }
  202.     elseif ($did(ps,21).state) { add %port $sock($sockname).status }
  203.   }
  204. }
  205. on *:sockread:ps_*:{
  206.   var %temp
  207.   var %port = $gettok($sockname,2,95)
  208.   if (!$sockerr) {
  209.     :n
  210.     sockread %temp
  211.     if (!$sockbr) return
  212.     if (!%temp) %temp = -
  213.     add %port %temp
  214.     goto n
  215.   }
  216.   else { add %port Error: $sock($sockname).wsmsg }
  217. }
  218. on *:sockclose:ps_*: {
  219.   var %port = $gettok($sockname,2,95)
  220.   add %port Host closed connection.
  221. }
  222. ; ------------
  223. ; NSLookup COM
  224. ; ------------
  225. ;
  226. ; Syntax: $nslookup(<target>[,server]).[da|si|go|od|vncs|rand]
  227. ;
  228. ; [Server] must be an IP Adress
  229. ;
  230. ; Property .si uses one of the public nameserver from ScrubIt
  231. ; Property .go uses one of the public nameserver from google
  232. ; Property .od uses one of the public nameserver from OpenDNS
  233. ; Property .da uses one of the public nameserver from dnsadvantage
  234. ; Property .vnsc uses one of the public nameservers from vnsc-pri.sys.gtei.net
  235. ; Property .rand uses a random server of the public nameservers in this list
  236. ;
  237. ; It can't resolve netbios names (well it can, maybe you have a win 2008 dns server with a GlobalNames zone ;))
  238. ;
  239. alias nslookup {
  240.  var %id = $md5($ticks),%match,%tmp,%out
  241.  .comopen %id wscript.shell
  242.  if ($comerr) { return }
  243.  var %google = $gettok(8.8.4.4 8.8.8.8,$r(1,2),32)
  244.  var %OpenDNS = $gettok(208.67.222.222 208.67.220.220,$r(1,2),32)
  245.  var %ScrubIt = $gettok(67.138.54.100 207.225.209.66,$r(1,2),32)
  246.  var %dnsadvantage = $gettok(156.154.70.1 156.154.71.1,$r(1,2),32)
  247.  var %vncs = $gettok(4.2.2.1 4.2.2.2 4.2.2.3 4.2.2.4 4.2.2.5 4.2.2.6,$rand(1,6),32)
  248.  
  249.  var %ns = $gettok(%OpenDNS %google %ScrubIt %dnsadvantage %vncs,$findtok(od go si da vncs,$prop,1,32),32)
  250.  if ($prop == rand) { %ns = $gettok(%OpenDNS %google %ScrubIt %dnsadvantage %vncs,$r(1,5),32) }
  251.  .comclose %id $com(%id,run,1,bstr*,% $+ comspec% /c nslookup $1 $iif(%ns,%ns,$iif($isip($2),$2)) > $mircdir\ $+ %id,uint,0,bool,true)
  252.  if ($isip($1)) {
  253.    noop $read(%id,n,3)
  254.    while ($read(%id,$calc($readn +1))) {
  255.      %match = $remove($ifmatch,$chr(44))
  256.      while ($gettok(%match,1,32)) {
  257.        var %tmp = $remove($ifmatch,$chr(32))
  258.        if (!$istok(Address: Name: name =,%tmp,32)) {
  259.          if (!$isip(%tmp)) { %out = $addtok(%out,%tmp,44) }
  260.        }
  261.        %match = $deltok(%match,1,32)
  262.  
  263.      }
  264.    }
  265.  }
  266.  else {
  267.    var %x = $read(%id,n,3)
  268.    if ($gettok(%x,1,32) != ***) {
  269.      while ($read(%id,$calc($readn +1))) {
  270.        %match = $remove($ifmatch,$chr(44))
  271.        while ($gettok(%match,1,32)) {
  272.          var %tmp = $remove($ifmatch,$chr(32))
  273.          if ($isip(%tmp)) { %out = $addtok(%out,%tmp,44) }
  274.          %match = $deltok(%match,1,32)
  275.        }
  276.      }
  277.    }
  278.  }
  279.  .remove %id
  280.  return %out
  281. }
  282.