Shell Basics
Anatomy of a Shell
CLI ( Command Language Interpreters)
Bind Shells
- A listener has to be stood up in the target system.
- Admins typically configure strict firewall rules and NAT on the edge of the network (public-facing), so we need to be already inside the internal network of the target system.
- Operating systems( windows and linux) often block incoming connections that aren't associated with a trusted network-based application, good luck evading that. Here is an example of how we can connect to a target system listening for a connection using netcat : Here is the listener that gets set up on the target system. ( Looks a lot like mkfifo payload for reverse shells, only the netcat command differs).
Reverse Shells
Everything Netcat
Payloads
Breaking down common One-Liners
mkfifo/Netcat and Bash one liner payload
Infamous Powershell One-Liner from Nishang Wordlist
⚠️ AV (Anti-Virus) Error Warning When we try to run the powershell one-liner reverse shell payload and the AV rejects it, changing the payload a little would do the job considering that AV only does static analysis of the code and checks the variable names, filenames, etc. against a database and if it finds any matches it flags and denies the execution of the script or executable. In our case, changing the payload to something like this would bypass AV signature scan:A simple sed command would do the job automatically.Powershell
MSFvenom Payload Crafting
Example of Creating a Stageless Payload with MSFvenom
A little deep dive into Windows Infiltration
Prominent Windows Exploits
- MS08-067: MS08-067 was a critical patch pushed out to many different Windows revisions due to an SMB flaw. This flaw made it extremely easy to infiltrate a Windows host. It was so efficient that the Conficker worm was using it to infect every vulnerable host it came across. Even Stuxnet took advantage of this vulnerability.
- Eternal Blue: MS17-010 is an exploit leaked in the Shadow Brokers dump from the NSA. This exploit was most notably used in the WannaCry ransomware and NotPetya cyber attacks. This attack took advantage of a flaw in the SMB v1 protocol allowing for code execution. EternalBlue is believed to have infected upwards of 200,000 hosts just in 2017 and is still a common way to find access into a vulnerable Windows host.
- Print Nightmare: A remote code execution vulnerability in the Windows Print Spooler. With valid credentials for that host or a low privilege shell, you can install a printer, add a driver that runs for you, and grants you system-level access to the host. This vulnerability has been ravaging companies through 2021.
- BlueKeep: CVE 2019-0708 is a vulnerability in Microsoft's RDP protocol that allows for Remote Code Execution. This vulnerability took advantage of a miss-called channel to gain code execution, affecting every Windows revision from Windows 2000 to Server 2008 R2.
- Sigred: CVE 2020-1350 utilized a flaw in how DNS reads SIG resource records. It is a bit more complicated than the other exploits on this list, but if done correctly, it will give the attacker Domain Admin privileges since it will affect the domain's DNS server which is commonly the primary Domain Controller.
- SeriousSam: CVE 2021-36934 exploits an issue with the way Windows handles permission on the C:\Windows\system32\config folder. Before fixing the issue, non-elevated users have access to the SAM database, among other files. This is not a huge issue since the files can't be accessed while in use by the pc, but this gets dangerous when looking at volume shadow copy backups. These same privilege mistakes exist on the backup files as well, allowing an attacker to read the SAM database, dumping credentials.
- Zerologon: CVE 2020-1472 is a critical vulnerability that exploits a cryptographic flaw in Microsoft’s Active Directory Netlogon Remote Protocol (MS-NRPC). It allows users to log on to servers using NT LAN Manager (NTLM) and even send account changes via the protocol. The attack can be a bit complex, but it is trivial to execute since an attacker would have to make around 256 guesses at a computer account password before finding what they need. This can happen in a matter of a few seconds.
Banner Grabbing using an Nmap Script
Bats, DLLs & MSI Files
-
- DLLs A Dynamic Linking Library (DLL) is a library file used in Microsoft operating systems to provide shared code and data that can be used by many different programs at once. These files are modular and allow us to have applications that are more dynamic and easier to update. As a pentester, injecting a malicious DLL or hijacking a vulnerable library on the host can elevate our privileges to SYSTEM and/or bypass User Account Controls.
-
- Batch Batch files are text-based DOS scripts utilized by system administrators to complete multiple tasks through the command-line interpreter. These files end with an extension of .bat. We can use batch files to run commands on the host in an automated fashion. For example, we can have a batch file open a port on the host, or connect back to our attacking box. Once that is done, it can then perform basic enumeration steps and feed us info back over the open port.
-
- VBS VBScript is a lightweight scripting language based on Microsoft's Visual Basic. It is typically used as a client-side scripting language in webservers to enable dynamic web pages. VBS is dated and disabled by most modern web browsers but lives on in the context of Phishing and other attacks aimed at having users perform an action such as enabling the loading of Macros in an excel document or clicking on a cell to have the Windows scripting engine execute a piece of code.
-
- MSI .MSI files serve as an installation database for the Windows Installer. When attempting to install a new application, the installer will look for the .msi file to understand all of the components required and how to find them. We can use the Windows Installer by crafting a payload as an .msi file. Once we have it on the host, we can run msiexec to execute our file, which will provide us with further access, such as an elevated reverse shell.
-
- Powershell Powershell is both a shell environment and scripting language. It serves as Microsoft's modern shell environment in their operating systems. As a scripting language, it is a dynamic language based on the .NET Common Language Runtime that, like its shell component, takes input and output as .NET objects. PowerShell can provide us with a plethora of options when it comes to gaining a shell and execution on a host, among many other steps in our penetration testing process.
Info: Windows AV evasion I have struggled in the past with AV evasion while creating an Active Directory lab, so I had to turn off Anti-Virus in order to attack, the tool below is utilized to obfuscate binaries. Here
Payload Delivery and Execution
- Impacket: Impacket is a toolset built in Python that provides us with a way to interact with network protocols directly. Some of the most exciting tools we care about in Impacket deal with psexec, smbclient, wmi, Kerberos, and the ability to stand up an SMB server.
- PayloadAllTheThings
- SMB: SMB can provide an easy to exploit route to transfer files between hosts. This can be especially useful when the victim hosts are domain joined and utilize shares to host data. We, as attackers, can use these SMB file shares along with C$ and admin$ to host and transfer our payloads and even exfiltrate data over the links.
- Remote execution via MSF: Built into many of the exploit modules in Metasploit is a function that will build, stage, and execute the payloads automatically.
- Other Protocols: When looking at a host, protocols such as FTP, TFTP, HTTP/S, and more can provide you with a way to upload files to the host. Enumerate and pay attention to the functions that are open and available for use. We focus a lot more on payload delivery in the File Transfers module in the blog.
Spawning Interactive Shells
- Perl : perl -e 'exec "/bin/sh";'
- Ruby: ruby: exec "/bin/sh" ( inside interpreter )
- awk: awk 'BEGIN {system("/bin/sh")}'
- Find: find / -name nameoffile -exec /bin/awk 'BEGIN {system("/bin/sh")}' \;
- Lua : lua: os.execute('/bin/sh')
- FInd with -exec : find . -exec /bin/sh \; -quit
- Vim: vim -c ':!/bin/sh'
- Vim escape:
vim
:set shell=/bin/sh
:shell
Web Shells
Laudanum
Antak Webshell
Considerations When Dealing with Webshell
- Web applications sometimes automatically delete files after a pre-defined period
- Limited interactivity with the operating system in terms of navigating the file system, downloading and uploading files, chaining commands together may not work (ex. whoami && hostname), slowing progress, especially when performing enumeration -Potential instability through a non-interactive web shell
- Greater chance of leaving behind proof that we were successful in our attack


