Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Shellcode

From Wikipedia, the free encyclopedia
(Redirected fromExecutable text)
Code intended as a payload to exploit a software vulnerability
This article includes alist of references,related reading, orexternal links,but its sources remain unclear because it lacksinline citations. Please helpimprove this article byintroducing more precise citations.(July 2025) (Learn how and when to remove this message)
"Shell code" redirects here. For code written in a shell's command language, seeShell script.
"Alphanumeric executable" redirects here. For executable code presented in hexadecimal format, seeHex file (disambiguation).

Shellcode isexecutable code intended to be used as apayload forexploiting asoftwarevulnerability. The term includesshell because the attack originally described an attack that opens acommand shell that the attacker can use to control the target machine, but any code that is injected to gain access that is otherwise not allowed can be called shellcode. For this reason, some consider the nameshellcode to be inaccurate.[1]

An attack commonly injectsdata that consists of executable code into aprocess before or as it exploits a vulnerability to gain control. Theprogram counter is set the shellcodeentry point so that that the shellcode runs. Deploying shellcode is often accomplished by including the code in a file that a vulnerable process downloads and then loads into its memory.

Common wisdom dictates that to maximum effectiveness, a shellcode payload should be small.[2]Machine code provides the flexibility needed to accomplish the goal. Shellcodeauthors leverage small opcodes to create compact shellcode.[3][4]

Types

[edit]
Local

A local shellcode attack allows an attacker to gain elevated access privilege on their computer. In some cases, exploiting a vulnerability can be achieved by causing an error such asbuffer overflow. If successful, the shellcode enables access to the machine via the elevated privileges granted to the targeted process.

Remote

A remote shellcode attack targets a process running on a remote machine – on the samelocal area network,intranet, or on theinternet. If successful, the shellcode provides access to the target machine across the network. The shellcode normally opens a TCP/IP socket connection to allow access to a shell on the target machine.

A remote shellcode attack can be categorized by its behavior. If the shellcode establishes the connection it is called areverse shell, or aconnect-back shellcode. On the other hand, if the attacker establishes the connection, the shellcode is called abindshell because the shellcodebinds to a certain port on the victim's machine. Abindshell random port skips the binding part and listens on a random port.[a] Asocket-reuse shellcode is an exploit that establishes a connection to the vulnerable process that is not closed before the shellcode runs so that the shellcode can re-use the connection to allow remote access. Socket re-using shellcode is more elaborate, since the shellcode needs to find out which connection to re-use and the machine may have many open connections.[5]

Afirewall can detect outgoing connections made by connect-back shellcode as well as incoming connections made by bindshells, and therefore, offers some protection against an attack. Even if the system is vulnerable, a firewall can prevent the attacker from connecting to the shell created by the shellcode. One reason why socket re-using shellcode is used is that it does not create new connections and, therefore, is harder to detect and block.

Download and execute

A download and execute shellcode attackdownloads andexecutesmalware on the target system. This type of shellcode does not spawn a shell, but rather instructs the machine to download a certain executable file from the network and execute it. Nowadays, it is commonly used indrive-by download attacks, where a victim visits a malicious webpage that in turn attempts to run such a download and execute shellcode in order to install software on the victim's machine.

A variation of this attack downloads and loads alibrary.[6][7] Advantages of this technique are that the code can be smaller, that it does not require the shellcode to spawn a new process on the target system, and that the shellcode does not need code to clean up the targeted process as this can be done by the library loaded into the process.

Staged

When the amount of data that an attacker can inject into the target process is too limited to achieve the desired effect, it may be possible to deploy shellcode in stages that progressively provide more access. The first stage might do nothing more than download the second stage than then provides the desired access.

Egg-hunt

An egg-hunt shellcode attack is a staged attack in which the attacker can inject shellcode into a process but does not know where in the process it is. A second-stage shellcode, generally smaller than the first, is injected into the process to search the process's address space for the first shellcode (theegg) and executes it.[8]

Omelet

An omelet shellcode attack, similar to egg-hunt, looks for multiple small blocks of data (eggs) and combines them into a larger block (omelet) that is then executed. This is used when an attacker is limited on the size of injected code but can inject multiple.[9]

Encoding

[edit]

Shellcode is often written in order to work around the restrictions on the data that a process will allow. General techniques include:

Optimize for size

Optimize the code to decrease its size.

Self-modifying code

Modify its own code before executing it to use byte values that are otherwise restricted.

Encryption

To avoidintrusion detection, encode as self-decrypting orpolymorphic.

Character encoding

An attack that targets a browser might obfuscate shellcode in aJavaScript string using an expanded character encoding.[10] For example, on theIA-32 architecture, here's two unencoded no-operation instructions (used in aNOP slide):

90             NOP90             NOP

As encoded:

Null-free

Shellcode must be written without zero-value bytes when it is intended to be injected into anull-terminated string that is copied in the target process via the usual algorithm (i.e.strcpy) of ending the copy at the first zero byte – called thenull character in commoncharacter sets. If the shellcode contained a null, the copy would be truncated and not function properly. To produce null-free code from code that contains nulls, one can replace machine instructions that contain zeroes with instructions that don't. For example, on theIA-32 architecture the instruction to set register EAX to 1 contains zeroes as part of the literal (1 expands to0x00000001).

B8 01000000MOV EAX,1

The following instructions accomplish the same goal (EAX containing 1) without embedded zero bytes by first setting EAX to 0, then incrementing EAX to 1:

33C0XOR EAX,EAX40INC EAX
Text

An alphanumeric shellcode consists of onlyalphanumeric characters (0–9, A–Z and a–z).[11][12] This type of encoding was created byhackers to obfuscate machine code inside what appears to beplain text. This can be useful to avoid detection of the code; to allow the code to pass through filters that scrub non-alphanumeric characters from strings.[b]. A similar type of encoding is calledprintable code and uses allprintable characters (alphanumeric plus symbols like !@#%^&*). A similarly restricted variant isECHOable code not containing any characters which are not accepted by theECHO command. It has been shown that it is possible to create shellcode that looks like normal text in English.[13]Writing such shellcode requires in-depth understanding of theinstruction set architecture of the target machines. It has been demonstrated that it is possible to write alphanumeric code that is executable on more than one machine,[14] thereby constitutingmulti-architecture executable code.

A work-around was published by Rix inPhrack 57[11] in which he shows that it is possible to turn any code into alphanumeric code. Often, self-modifying code is leveraged because it allows the code to have byte values that otherwise are not allowed by replacing coded values at runtime. A self-modifying decoder can be created that initially uses only allowed bytes. The main code of the shellcode is encoded, also only using bytes in the allowed range. When the output shellcode is run, the decoder modifies its code to use instructions it requires and then decodes the original shellcode. After decoding the shellcode, the decoder transfers control to it. It has been shown that it is possible to create arbitrarily complex shellcode that looks like normal English text.[13]

Modern software usesUnicode to supportInternationalization and localization. Often, inputASCII text is converted to Unicode before processing. When an ASCII (Latin-1 in general) character is transformed to UTF-16 (16-bit Unicode), a zero byte is inserted after each byte (character) of the original text. Obscou proved inPhrack 61[12] that it is possible to write shellcode that can run successfully after this transformation. Programs that can automatically encode any shellcode into alphanumeric UTF-16-proof shellcode exist, based on the same principle of a small self-modifying decoder that decodes the original shellcode.

Compatibility

[edit]

Generally, shellcode is deployed as machine code since it affords relatively unprotected access to the target process. Since machine code is compatible within a relatively narrow computing context (processor,operating system and so on), a shellcode fragment has limitedcompatibility. Also, since a shellcode attack tends to work best when the code is small and targeting multiple exploits increases the size, typically the code targets only one exploit. None the less, a single shellcode fragment can work for multiple contexts and exploits.[15][16][17] Versatility can be achieved by creating a single fragment that contains an implementation for multiple contexts. Common code branches to the implementation for the runtime context.

Analysis

[edit]

As shellcode is generally not executable on its own, in order to study what it does, it is typically loaded into a special process. A common technique is to write a smallC program that contains the shellcode as data (i.e. in a byte buffer), and transfers control to the instructions encoded in the datafunction pointer or inlineassembly code). Another technique is to use an online tool, such asshellcode_2_exe, to embed the shellcode into a pre-made executable husk which can then be analyzed in a standard debugger. Specialized shellcode analysis tools also exist, such as the iDefense sclog project (originally released in 2005 in the Malcode Analyst Pack). Sclog is designed to load external shellcode files and execute them within an API logging framework. Emulation-based shellcode analysis tools also exist such as thesctest application which is part of the cross-platform libemu package. Another emulation-based shellcode analysis tool, built around the libemu library, isscdbg which includes a basic debug shell and integrated reporting features.

See also

[edit]

Notes

[edit]
  1. ^Thebindshell random port is the smallest stable bindshell shellcode forx86_64 available to date.
  2. ^in part, such filters were a response to non-alphanumeric shellcode exploits

References

[edit]
  1. ^Foster, James C.; Price, Mike (2005-04-12).Sockets, Shellcode, Porting, & Coding: Reverse Engineering Exploits and Tool Coding for Security Professionals. Elsevier Science & Technology Books.ISBN 1-59749-005-9.
  2. ^Anley, Chris; Koziol, Jack (2007).The shellcoder's handbook: discovering and exploiting security holes (2 ed.). Indianapolis, Indiana, UA: Wiley.ISBN 978-0-470-19882-7.OCLC 173682537.
  3. ^Foster, James C. (2005).Buffer overflow attacks: detect, exploit, prevent. Rockland, MA, USA: Syngress.ISBN 1-59749-022-9.OCLC 57566682.
  4. ^"Tiny Execve sh - Assembly Language - Linux/x86".GitHub. Retrieved2021-02-01.
  5. ^BHA (2013-06-06)."Shellcode/Socket-reuse". Retrieved2013-06-07.
  6. ^SkyLined (2010-01-11)."Download and LoadLibrary shellcode released". Archived fromthe original on 2010-01-23. Retrieved2010-01-19.
  7. ^"Download and LoadLibrary shellcode for x86 Windows". 2010-01-11. Retrieved2010-01-19.
  8. ^Skape (2004-03-09)."Safely Searching Process Virtual Address Space"(PDF). nologin. Retrieved2009-03-19.
  9. ^SkyLined (2009-03-16)."w32 SEH omelet shellcode". Skypher.com. Archived fromthe original on 2009-03-23. Retrieved2009-03-19.
  10. ^"JavaScript large number of unescape patterns detected". Archived fromthe original on 2015-04-03.
  11. ^abrix (2001-08-11)."Writing ia32 alphanumeric shellcodes".Phrack.0x0b (57). Phrack Inc. #0x0f of 0x12.Archived from the original on 2022-03-08. Retrieved2022-05-26.
  12. ^abobscou (2003-08-13)."Building IA32 'Unicode-Proof' Shellcodes".Phrack.11 (61). Phrack Inc. #0x0b of 0x0f.Archived from the original on 2022-05-26. Retrieved2008-02-29.
  13. ^abMason, Joshua; Small, Sam; Monrose, Fabian; MacManus, Greg (November 2009).English Shellcode(PDF). Proceedings of the 16th ACM conference on Computer and Communications Security. New York, NY, USA. pp. 524–533.Archived(PDF) from the original on 2022-05-26. Retrieved2010-01-10. (10 pages)
  14. ^"Multi-architecture (x86) and 64-bit alphanumeric shellcode explained". Blackhat Academy. Archived fromthe original on 2012-06-21.
  15. ^eugene (2001-08-11)."Architecture Spanning Shellcode".Phrack. Phrack Inc. #0x0e of 0x12.Archived from the original on 2021-11-09. Retrieved2008-02-29.
  16. ^nemo (2005-11-13)."OSX - Multi arch shellcode".Full disclosure.Archived from the original on 2022-05-26. Retrieved2022-05-26.
  17. ^Cha, Sang Kil; Pak, Brian;Brumley, David;Lipton, Richard Jay (2010-10-08) [2010-10-04].Platform-Independent Programs(PDF). Proceedings of the 17th ACM conference on Computer and Communications Security (CCS'10). Chicago, Illinois, USA:Carnegie Mellon University, Pittsburgh, Pennsylvania, USA /Georgia Institute of Technology, Atlanta, Georgia, USA. pp. 547–558.doi:10.1145/1866307.1866369.ISBN 978-1-4503-0244-9.Archived(PDF) from the original on 2022-05-26. Retrieved2022-05-26.[1] (12 pages) (See also:[2])

External links

[edit]
Threats
vectorial version
vectorial version
Defenses
Related
security
topics
Retrieved from "https://en.wikipedia.org/w/index.php?title=Shellcode&oldid=1315865784#Alphanumeric"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp