ak47suk1

make your own ap [LATEST VERSION]

Oct 15th, 2011
194
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #y0-
  3.  
  4.  
  5. # dependencies
  6. # sudo apt-get install dnsmasq hostapd isc-dhcp-server
  7.  
  8. version=0.1
  9. show_help(){
  10.         echo "A rogue AP setup utility v$version inspired from Airsnarf Shmoo. "
  11.     echo "Copyright (c) 2011 USIM Student Batch 2007-2011. All rights reserved"
  12.     echo
  13.         echo "Usage:    $0  [options]"
  14.         echo "Options:"
  15.         echo "-s    : show config"
  16.         echo "-r    : run this config"
  17.         echo "-h    : show this help message and exit"
  18. }
  19. show_config(){
  20. head -n 68 $0
  21. }
  22.  
  23. while [[ $# != 0 ]]; do
  24.     arg_name=$1; shift
  25.     case "$arg_name" in
  26.       -h) show_help; exit 0;;
  27.       -s) show_config; exit 0;;
  28.       -r) t=$arg_name;break;;
  29.       *) echo "invalid option: $1"; show_help;exit 1;;
  30.     esac
  31. done
  32. [ "$t" != "-r" ] && { show_help; exit 1; }
  33.  
  34.  
  35. ################################################
  36. # Here are some variables you may want to edit
  37. ################################################
  38. BMODE="non-bridge" # BMODE can be: bridge, non-bridge or karma
  39. MODE="simple" # MODE can be: simple, mallory, sslstrip, captive, milk
  40.  
  41. INET_IFACE="tun0" #ppp0 #tun0
  42. # INET_IFACE="tun0" <-- tukar kepada ppp0,eth0 bergantung pada interface 3g dongle/VPN/Ethernet
  43. HOSTAP_WIFI_IFACE="wlan1" # Tested on ath5k/ath9k/rt73usb based cards
  44. BRIDGE_IFACE="br0"
  45. CHAN="7" # tengok kad wifi support sampai channel berapa
  46. SSID="mysabily.blogspot.com" # Boleh tukarSSID kepada nama lain
  47.  
  48. INET_GW="10.8.0.6" #10.8.0.6 # Set external IP di sini check guna whatismyipaddress.com
  49. LAN_IP="192.168.2.1" # tukar ikut citarasa nak guna class A,B,C local ipv4
  50. NETMASK="255.255.255.0"
  51. NETWORK="192.168.2.0/24"
  52. BROADCAST_IP="192.168.2.255"
  53. SUBNET="192.168.2.0"
  54. RANGE_IP="192.168.2.3 192.168.2.254"
  55. DHCP_MIN="192.168.2.3"
  56. DHCP_MAX="192.168.2.254"
  57. DOMAIN="usim.edu.my"
  58. OPTION_NETBIOS_NAME_SERVERS="192.168.2.252"
  59. ACL_LOCALNET_SRC="192.168.0.0/16"
  60. #OPDNS="208.67.222.220, 208.67.222.222, 4.2.2.1, 4.2.2.2, 208.67.216.132, 208.67.216.132"
  61. OPDNS="8.8.8.8,8.8.4.4"
  62. #OPDNS="58.71.136.10,58.71.132.10" # Set DNS di sini
  63. DNS="$INET_GW, $OPDNS" ##DNSpppX = "YOUR ISP DNS SERVER, $OPDNS"
  64. #DNS="$OPDNS"
  65.  
  66. #payload="" # payload can be : sbd/vnc/wkv/other (what to upload to the user). vnc=remote desktop, sbd=shell, wkv=View WiFi keys. (/path/to/file), only used if payload is "other"
  67. #backdoorPath="/tmp/backdoor.exe"
  68. port=$(shuf -i 2000-65000 -n 1)
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. echo "----------------------------------------------------------------------"
  80. echo "A rogue AP setup utility v$version inspired from Airsnarf Shmoo. "
  81. echo "Copyright (c) 2011 USIM Student Batch 2007-2011. All rights reserved"
  82. echo "----------------------------------------------------------------------"
  83.  
  84. echo  "[*] Testing internet connection...";
  85. command=$(ping -I $INET_IFACE -c 1 google.com |grep "64 bytes from" |cut -d' ' -f 4);
  86. if [ -z $command ] ; then echo "[!] Internet access failed. "; exit 1 ; else echo "[-] Got internet access..." ; fi;
  87.  
  88. mkdir -p "$(pwd)/tmp/"
  89. HOME_DIR="$(pwd)/tmp"
  90.  
  91. # Create the hostapd.conf
  92. mkdir -p /tmp/hostapd > /dev/null 2>&1
  93. rm /tmp/hostapd/hostapd.conf > /dev/null 2>&1
  94. rm /tmp/hostapd/hostapd.pid > /dev/null 2>&1
  95.  
  96. cat > /tmp/hostapd/hostapd.conf << EOF
  97. driver=nl80211
  98. logger_syslog=-1
  99. logger_syslog_level=2
  100. logger_stdout=-1
  101. logger_stdout_level=1
  102. ssid=$SSID
  103. hw_mode=g
  104. channel=$CHAN
  105. beacon_int=100
  106. dtim_period=2
  107. max_num_sta=255
  108. rts_threshold=2347
  109. fragm_threshold=2346
  110. macaddr_acl=0
  111. auth_algs=3
  112. ignore_broadcast_ssid=0
  113. #wmm_enabled=1
  114. eapol_key_index_workaround=0
  115. eap_server=0
  116. own_ip_addr=127.0.0.1
  117. # WPA settings. We'll use stronger WPA2
  118. # bit0 = WPA
  119. # bit1 = IEEE 802.11i/RSN (WPA2) (dot11RSNAEnabled)
  120. wpa=2
  121.  
  122. # Preshared key of between 8-63 ASCII characters.
  123. # If you define the key in here, make sure that the file is not readable
  124. # by anyone but root. Alternatively you can use a separate file for the
  125. # key; see original hostapd.conf for more information.
  126. # Set WPA key di sini
  127. wpa_passphrase=passworddisini
  128.  
  129. # Key management algorithm. In this case, a simple pre-shared key (PSK)
  130. wpa_key_mgmt=WPA-PSK
  131.  
  132. # The cipher suite to use. We want to use stronger CCMP cipher.
  133. wpa_pairwise=CCMP
  134.  
  135. # Change the broadcasted/multicasted keys after this many seconds.
  136. wpa_group_rekey=600
  137.  
  138. # Change the master key after this many seconds. Master key is used as a basis
  139. # (source) for the encryption keys.
  140. wpa_gmk_rekey=86400
  141.  
  142. EOF
  143.  
  144. echo "interface=$HOSTAP_WIFI_IFACE" >> /tmp/hostapd/hostapd.conf
  145.  
  146. echo "INTERFACES=\"\"" > /etc/default/dhcp3-server
  147.  
  148. if [ "$BMODE" == "non-bridge" ]; then
  149. ifconfig $HOSTAP_WIFI_IFACE down && sleep 2
  150. ifconfig $HOSTAP_WIFI_IFACE up && sleep 2
  151. ifconfig $HOSTAP_WIFI_IFACE $LAN_IP netmask $NETMASK
  152. route add -net $SUBNET netmask $NETMASK gw $LAN_IP
  153.  
  154. echo -e "[*] Starting DHCP Server.. "
  155.  
  156. # Create custom dhcpd.conf
  157. path="$HOME_DIR/dhcpd.conf"
  158. if [ -e "$path" ] ; then rm "$path"; fi
  159. echo -e "#
  160. ddns-update-style none;
  161. ignore client-updates; # Ignore all client requests for DDNS update
  162. authoritative;
  163. default-lease-time 86400; # 24 hours
  164. max-lease-time 172800;    # 48 hours
  165. log-facility local7;\n
  166. subnet $SUBNET netmask $NETMASK {
  167. range $RANGE_IP;
  168. option routers $LAN_IP;
  169. option subnet-mask $NETMASK;
  170. option broadcast-address  $BROADCAST_IP;
  171. option domain-name \"$DOMAIN\"; " >> $path
  172.  
  173. echo " option domain-name-servers $DNS;" >> $path
  174. #echo " option domain-name-servers $LAN_IP;" >> $path #non tranparant
  175.  
  176. echo -e " option netbios-name-servers $OPTION_NETBIOS_NAME_SERVERS;\n}" >> $path
  177.  
  178. cp $HOME_DIR/dhcpd.conf /etc/dhcp3/dhcpd.conf
  179. rm /var/run/dhcpd.pid
  180. ln -s /var/run/dhcp3-server/dhcpd.pid /var/run/dhcpd.pid
  181. dhcpd -cf /etc/dhcp/dhcpd.conf $HOSTAP_WIFI_IFACE -pf /var/run/dhcpd.pid
  182.  
  183. echo -e "[*] Starting DNS forwarder... "
  184.  
  185. path="$HOME_DIR/dnsmasq.conf"
  186. if [ -e "$path" ] ; then rm "$path" ; fi
  187. echo -e "#
  188. interface=$LAN_IFACE
  189. domain=$DOMAIN
  190. #dhcp-range=$DHCP_MIN,$DHCP_MAX,24h
  191. #dhcp-authoritative
  192. #dhcp-option=3,$LAN_IP # Gateway" >> $path
  193. #echo -e "dhcp-option=6,$LAN_IP # DNS" >> $path #non tranparant
  194. echo -e "dhcp-option=6,$DNS # DNS" >> $path ; fi
  195. echo -e "log-queries
  196. #log-dhcp
  197. log-facility="$HOME_DIR/dnsmasq.log"" >> $path
  198.  
  199. # Solve our DNS Forwarder
  200. dnsmasq -C $HOME_DIR/dnsmasq.conf&
  201.  
  202. ##########################################################################
  203. # Simple WLAN setup (clients can access Internet)
  204. if [ $MODE = "simple" ];then echo -e "[*] Starting simple WLAN setup...."
  205. iptables --flush
  206. iptables --table nat --flush
  207. iptables --delete-chain
  208. iptables --table nat --delete-chain
  209.  
  210. iptables -t nat -A POSTROUTING -o $INET_IFACE -j MASQUERADE
  211. iptables -A FORWARD -i $HOSTAP_WIFI_IFACE -j ACCEPT
  212. #iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to $INET_GW
  213.  
  214. echo 1 > /proc/sys/net/ipv4/ip_forward
  215. sleep 1
  216.  
  217. /etc/init.d/dhcp3-server restart > /dev/null 2>&1
  218. sleep 1
  219.  
  220. echo "Starting AP..."
  221. hostapd -P /tmp/hostapd/hostapd.pid /tmp/hostapd/hostapd.conf
  222.  
  223. fi
RAW Paste Data