Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.60 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. # this is a work in progress, im going to eventuall make a complete handler for wireless router .
  3. # I started trying to make a WAP software in rub but after a while I started realizing that I shouldnt reinvent the wheel
  4. # 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
  5. #for some packet manipulation in the stream using scapy.
  6. #The configurtation options are all constants, i figured that instead of asking each time (since people generally have a
  7. #consistant setup) you set them in the code, the Class "packet_filter" is the filter (no really?!?!) i generally use nested ifs
  8. # for the hueristics but you can do whatever here, the logger is being worked on as you read this.
  9.  
  10. #TODO: plucking images is an interesting idea.
  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 'packetfu'
  16.  
  17.  
  18. #Handles encryption
  19. #example
  20. #   #preparing my balls for encryption
  21. #   balls = Encryption.new("balls")
  22. #   #encrypting my balls
  23. #   balls.encrypt_payload
  24.  
  25.  
  26. class Encryption
  27.     def initialize (string)
  28.         @string = string
  29.     end
  30.     #encrypts
  31.     def encrypt_payload
  32.         cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
  33.         cipher.encrypt
  34.         cipher.key = WAPinit::KEY
  35.         cipher.iv = WAPinit::IV
  36.         cipher.update(@string) + cipher.final
  37.        
  38.     end
  39.     #decrypts
  40.     def decrypt_payload
  41.         cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
  42.         cipher.decrypt
  43.         cipher.key = WAPinit::KEY
  44.         cipher.iv = WAPinit::IV
  45.         cipher.update(@string) + cipher.final
  46.     end
  47.    
  48. end
  49.  
  50.  
  51. #instances of this class start the show
  52. class WAPinit
  53.  
  54. printf "\n\033[00;31m[SYSTEM]\033[00m Initializing Constants\n"
  55. printf "\033[00;35m===============================================================\033[00m\n"
  56.  
  57.  
  58. #general config
  59. KEY = "qwertyuiopasdfghjklzxcvbnmqwerty"
  60. IV = "qwertyuiopasdfghjklzxcvbnmqwerty"
  61. $ACTBAD=true
  62. $VERBOSE = true
  63. LOGGING= true
  64. MONITOR="mon0"
  65. EXTIF="eth1"
  66. TUNNEL="at0"
  67. INTIF="wlan1"
  68. TTY="/dev/tty10"
  69. CHAN = "9"
  70. ESSID="Firefly"
  71.  
  72.  
  73. #DHCP config
  74. RANGE="192.168.1.2 192.168.1.254"
  75. SCOPE="192.168.1.0"
  76. GATEWAY="192.168.1.1"
  77. MASK="255.255.255.0"
  78. BROADCAST="192.168.1.255"
  79. DOMAIN="cerberusrouter.net"
  80. DNS1="208.67.222.222"
  81. DNS2="208.67.220.220"
  82.  
  83.  
  84. #file contents of the bind and DHCP servers
  85. bind = <<BIND
  86. options {
  87.     directory "/var/cache/bind";
  88.    
  89.     forwarders {
  90.         #{GATEWAY};
  91.        
  92.     };
  93.  
  94.     auth-nxdomain no;    # conform to RFC1035
  95.     listen-on-v6 { any; };
  96. };
  97. BIND
  98.  
  99.  
  100. dhcp3 = <<DHCP
  101. ddns-update-style interim;                                  
  102. ignore client-updates;
  103.  
  104. subnet #{SCOPE} netmask #{MASK} {
  105.  
  106.         range #{RANGE};                  
  107.            option subnet-mask              #{MASK};    # Default subnet mask to be used by DHCP clients
  108.            option broadcast-address        #{BROADCAST};    # Default broadcast address to be used by DHCP clients
  109.            option routers                  #{GATEWAY};      # Default gateway to be used by DHCP clients
  110.            option domain-name              "#{DOMAIN}";
  111.            option domain-name-servers      #{DNS1}, #{DNS2};           # Default DNS to be used by DHCP clients
  112. }
  113. #         DHCP requests are not forwarded. Applies when there is more than one ethernet device and forwarding is configured.
  114. #       option ipforwarding off;
  115.  
  116.          default-lease-time 21600;                            # Amount of time in seconds that a client may keep the IP address
  117.         max-lease-time 43200;
  118.  
  119.         option time-offset              -18000;              # Eastern Standard Time
  120. #       option ntp-servers              192.168.1.1;         # Default NTP server to be used by DHCP clients
  121. DHCP
  122.  
  123.          
  124. #Heuristics for the execution of aircrack suite and monitoring tools and pretty much what ever else you want to add
  125. #this uses nested IF's to determine if the application is running, if it isnt it will start it
  126. if `ifconfig`.match(/mon[0-9]/)
  127.   printf "\033[00;31m[SYSTEM] Monitor mode Previously Enabled, Skipping\033[00m \n"
  128.     if `ifconfig`.match(/at[0-9]/) != true
  129.      printf "\033[00;31m[SYSTEM]\033[00mActivating Wireless Access Point \n"
  130.      pid = fork do    
  131.      system("airbase-ng -e #{ESSID} -a DE:AD:BE:EF:CA:FE -v -v -c #{CHAN} -I 5000  #{MONITOR} 2>&1")
  132.        end
  133.       Process.detach(pid)
  134.     else printf "\033[00;31m[SYSTEM]WAP Already Active Skipping (if you did not know this please 'killall -9 airbase') \033[00m \n"
  135.    end
  136.  
  137.   elsif `ifconfig`.match(/wlan[0-9]/)
  138.   `gksu "airmon-ng start #{EXTIF} #{CHAN}"`
  139.    printf "\033[00;31m[SYSTEM]\033[00m Monitor Mode Enabled on #{INTIF}  \n"
  140.    printf "\033[00;31m[SYSTEM]\033[00mActivating Wireless Access Point \n"
  141.     pid = fork do
  142.      $WAP = system("airbase-ng -e #{ESSID} -a DE:AD:BE:EF:CA:FE -v -v -c #{CHAN} -I 5000 #{MONITOR} 2>&1")
  143.    end
  144.    Process.detach(pid)
  145. end
  146.  
  147.  
  148. printf "\033[00;31m[SYSTEM]\033[00m   TTY output Being Directed to \033[00;31m#{TTY}\033[00m\n"
  149. printf "\033[00;34m[NETWORK]\033[00m External Interface: \033[00;31m#{EXTIF}\033[00m\n"
  150. printf "\033[00;34m[NETWORK]\033[00m Monitor Interface:  \033[00;31m #{MONITOR}\033[00m\n"
  151. printf "\033[00;34m[NETWORK]\033[00m Internal Interface: \033[00;31m#{INTIF}\033[00m\n"
  152. printf "\033[00;34m[NETWORK]\033[00m Tunnnel Interface:  \033[00;31m #{TUNNEL}\033[00m\n"
  153.  
  154.  
  155. #begin the router-fu!
  156. `modprobe ip_tables`
  157. `modprobe iptable_filter`
  158. `modprobe ip_conntrack`
  159. `modprobe ip_conntrack_ftp`
  160. `modprobe ip_conntrack_irc`
  161. `modprobe iptable_nat`
  162. `modprobe ip_nat_ftp`
  163. `modprobe ip_nat_irc`
  164.  
  165. printf "\033[00;31m[SYSTEM]\033[00m Done loading modules\n"
  166. printf "\033[00;31m[SYSTEM]\033[00m Enabling DynamicAddr\n"
  167. `echo "1" > /proc/sys/net/ipv4/ip_dynaddr`
  168.  
  169. printf "\033[00;31m[SYSTEM]\033[00m Resetting IPTables Rules\n"
  170. `iptables --table nat --flush`
  171. `iptables --delete-chain`
  172. `iptables --flush`
  173. `iptables -P INPUT ACCEPT`
  174. `iptables -F INPUT `
  175. `iptables -P OUTPUT ACCEPT`
  176. `iptables -F OUTPUT `
  177. `iptables -P FORWARD DROP`
  178. `iptables -F FORWARD `
  179. `iptables -t nat -F`
  180. printf "\n\033[00;31m[SYSTEM]\033[00m Configuring Routing Tables\n"
  181. printf "\033[00;35m===============================================================\033[00m\n"
  182. printf "\033[00;34m          [NETWORK]\033[00m Forwarding DNS to Tunnel\n"
  183. `iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to #{GATEWAY}` #dns
  184. printf "\033[00;34m          [NETWORK]\033[00m Forwarding Subnet to Tunnel\n"
  185. `iptables -A FORWARD -i #{INTIF} -o #{TUNNEL} -j ACCEPT`
  186. printf "\033[00;34m          [NETWORK]\033[00m Forwarding Tunnel to Subnet\n"
  187. `iptables -A FORWARD -i #{TUNNEL} -o #{INTIF} -j ACCEPT`
  188. `iptables -A FORWARD -j LOG`
  189. printf "\033[00;34m          [NETWORK]\033[00m Enabling NAT on \033[00;31m#{TUNNEL}\033[00m\n"
  190. `iptables -t nat -A POSTROUTING -o #{TUNNEL} -j MASQUERADE`
  191. `echo "1" > /proc/sys/net/ipv4/ip_forward`
  192. printf "\033[00;35m===============================================================\033[00m\n"
  193. printf "\033[00;31m[SYSTEM]\033[00m IPTables Configured\n"
  194. printf "\n\033[00;31m[SYSTEM]\033[00m Configuring DHCP\n"
  195. printf "\033[00;35m===============================================================\033[00m\n"
  196. `ifconfig at0 up`
  197. `ifconfig at0 #{GATEWAY} netmask #{MASK}`
  198. `ifconfig at0 mtu 1500`
  199. dhcpconf = File.open("/etc/dhcp3/dhcpd.conf", "w")
  200. dhcpconf.syswrite(dhcp3)
  201. printf `dhcpd3 #{TUNNEL}`
  202. printf "\033[00;35m===============================================================\033[00m\n"
  203. printf "\033[00;31m[SYSTEM]\033[00m DHCP Server Configured\n"
  204. printf "\n\033[00;31m[SYSTEM]\033[00m Configuring DNS\n"
  205. printf "\033[00;35m===============================================================\033[00m\n"
  206. dnsf = File.open("/etc/bind/named.conf.options", "w")
  207. dnsf.syswrite(bind)
  208. printf `/etc/init.d/bind9 restart`
  209. printf "\033[00;31m[SYSTEM]\033[00m DNS Caching Configured\n"
  210. printf "\033[00;35m===============================================================\033[00m\n"
  211. `notify-send "Cerberus - Wireless Access Point initialized`
  212. end
  213.  
  214.  
  215. #a sniffer just cause i dont have teh skillz yet for coding one in C
  216. #class Packet_filter
  217. #  def initialize(filter,iface)
  218. #    @filter = filter
  219. #    @iface  = iface
  220. #  end
  221. #    station = PacketFu::Capture.new(:iface => @iface, :start => true , :filter => @filter)
  222. #      loop {
  223. #        station.stream.each do |packet|
  224. #          packet_object = PacketFu::Packet.parse(packet)
  225.           #if packet_object.is_arp?  
  226.           #printf "\033[00;31m[Network]ARP: From #{packet_object.ip_saddr} to #{packet_object.ip_saddr}"
  227.           #else printf "asdf\n"
  228.           #end
  229. #        end
  230. #      }
  231.      
  232. #end
  233.    
  234. class Logger
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242. end
  243. WAPinit.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement