네! 가능해요.
일반적으로 한 argv 값 안에 엄청 긴 문자열이 들어가게 되면 argument list too long 이라는 게 뜨게 되지만, 여러개로 나눈다면 달라져요.
물론 argc를 체크한다면 그러면 안되겠죠..
아래는 간단한 프로그램의 결과에요. 프로그램 내용은..
이에요. 1초를 쉬는 이유는 그 뒤에 stack의 할당 범위를 알아내기 위해서죠.
ebp 는 알아낼필요 없더라구요. :(
아래는 결과에요.
parallels@ubuntu:~$ ./argsled `python -c 'print "A"*100000'` `python -c 'print "A"*100000'` `python -c 'print "A"*100000'` `python -c 'print "A"*100000'` `python -c 'print "A"*100000'` & sleep 0.2; grep stack /proc/$(pgrep argsled)/maps
네, 스택의 끝부분인 fff88000 에서 argv[1]의 주소인 fff0b728을 빼본다면 510168 이 나올거에요.
저는 500000개만큼의 A를 넣어줬죠. 거기다가 널바이트(argv 구분자)를 합하면 500005개를 넣었네요. 거기다가 프로그램의 실행 이름, ./argsled의 길이를 합하면 500014가 되는군요.
중간에 널바이트가 끼는데, 이 부분은 아래의 표를 참고하시면 될거에요.
[nop*10][0~255][0] 의 옵코드에요.
0x0 (16L, 2L, 'ADD [EAX], AL', '0000')
0x1 (16L, 2L, 'ADD [EAX], EAX', '0100')
0x2 (16L, 2L, 'ADD AL, [EAX]', '0200')
0x3 (16L, 2L, 'ADD EAX, [EAX]', '0300')
0x4 (16L, 2L, 'ADD AL, 0x0', '0400')
0x5 (17L, 1L, 'DB 0x0', '00')
0x6 (17L, 1L, 'DB 0x0', '00')
0x7 (17L, 1L, 'DB 0x0', '00')
0x8 (16L, 2L, 'OR [EAX], AL', '0800')
0x9 (16L, 2L, 'OR [EAX], EAX', '0900')
0xa (16L, 2L, 'OR AL, [EAX]', '0a00')
0xb (16L, 2L, 'OR EAX, [EAX]', '0b00')
0xc (16L, 2L, 'OR AL, 0x0', '0c00')
0xd (17L, 1L, 'DB 0x0', '00')
0xe (17L, 1L, 'DB 0x0', '00')
0xf (17L, 1L, 'DB 0x0', '00')
0x10 (16L, 2L, 'ADC [EAX], AL', '1000')
0x11 (16L, 2L, 'ADC [EAX], EAX', '1100')
0x12 (16L, 2L, 'ADC AL, [EAX]', '1200')
0x13 (16L, 2L, 'ADC EAX, [EAX]', '1300')
0x14 (16L, 2L, 'ADC AL, 0x0', '1400')
0x15 (17L, 1L, 'DB 0x0', '00')
0x16 (17L, 1L, 'DB 0x0', '00')
0x17 (17L, 1L, 'DB 0x0', '00')
0x18 (16L, 2L, 'SBB [EAX], AL', '1800')
0x19 (16L, 2L, 'SBB [EAX], EAX', '1900')
0x1a (16L, 2L, 'SBB AL, [EAX]', '1a00')
0x1b (16L, 2L, 'SBB EAX, [EAX]', '1b00')
0x1c (16L, 2L, 'SBB AL, 0x0', '1c00')
0x1d (17L, 1L, 'DB 0x0', '00')
0x1e (17L, 1L, 'DB 0x0', '00')
0x1f (17L, 1L, 'DB 0x0', '00')
0x20 (16L, 2L, 'AND [EAX], AL', '2000')
0x21 (16L, 2L, 'AND [EAX], EAX', '2100')
0x22 (16L, 2L, 'AND AL, [EAX]', '2200')
0x23 (16L, 2L, 'AND EAX, [EAX]', '2300')
0x24 (16L, 2L, 'AND AL, 0x0', '2400')
0x25 (17L, 1L, 'DB 0x0', '00')
0x26 (17L, 1L, 'DB 0x0', '00')
0x27 (17L, 1L, 'DB 0x0', '00')
0x28 (16L, 2L, 'SUB [EAX], AL', '2800')
0x29 (16L, 2L, 'SUB [EAX], EAX', '2900')
0x2a (16L, 2L, 'SUB AL, [EAX]', '2a00')
0x2b (16L, 2L, 'SUB EAX, [EAX]', '2b00')
0x2c (16L, 2L, 'SUB AL, 0x0', '2c00')
0x2d (17L, 1L, 'DB 0x0', '00')
0x2e (17L, 1L, 'DB 0x0', '00')
0x2f (17L, 1L, 'DB 0x0', '00')
0x30 (16L, 2L, 'XOR [EAX], AL', '3000')
0x31 (16L, 2L, 'XOR [EAX], EAX', '3100')
0x32 (16L, 2L, 'XOR AL, [EAX]', '3200')
0x33 (16L, 2L, 'XOR EAX, [EAX]', '3300')
0x34 (16L, 2L, 'XOR AL, 0x0', '3400')
0x35 (17L, 1L, 'DB 0x0', '00')
0x36 (17L, 1L, 'DB 0x0', '00')
0x37 (17L, 1L, 'DB 0x0', '00')
0x38 (16L, 2L, 'CMP [EAX], AL', '3800')
0x39 (16L, 2L, 'CMP [EAX], EAX', '3900')
0x3a (16L, 2L, 'CMP AL, [EAX]', '3a00')
0x3b (16L, 2L, 'CMP EAX, [EAX]', '3b00')
0x3c (16L, 2L, 'CMP AL, 0x0', '3c00')
0x3d (17L, 1L, 'DB 0x0', '00')
0x3e (17L, 1L, 'DB 0x0', '00')
0x3f (17L, 1L, 'DB 0x0', '00')
0x40 (17L, 1L, 'DB 0x0', '00')
0x41 (17L, 1L, 'DB 0x0', '00')
0x42 (17L, 1L, 'DB 0x0', '00')
0x43 (17L, 1L, 'DB 0x0', '00')
0x44 (17L, 1L, 'DB 0x0', '00')
0x45 (17L, 1L, 'DB 0x0', '00')
0x46 (17L, 1L, 'DB 0x0', '00')
0x47 (17L, 1L, 'DB 0x0', '00')
0x48 (17L, 1L, 'DB 0x0', '00')
0x49 (17L, 1L, 'DB 0x0', '00')
0x4a (17L, 1L, 'DB 0x0', '00')
0x4b (17L, 1L, 'DB 0x0', '00')
0x4c (17L, 1L, 'DB 0x0', '00')
0x4d (17L, 1L, 'DB 0x0', '00')
0x4e (17L, 1L, 'DB 0x0', '00')
0x4f (17L, 1L, 'DB 0x0', '00')
0x50 (17L, 1L, 'DB 0x0', '00')
0x51 (17L, 1L, 'DB 0x0', '00')
0x52 (17L, 1L, 'DB 0x0', '00')
0x53 (17L, 1L, 'DB 0x0', '00')
0x54 (17L, 1L, 'DB 0x0', '00')
0x55 (17L, 1L, 'DB 0x0', '00')
0x56 (17L, 1L, 'DB 0x0', '00')
0x57 (17L, 1L, 'DB 0x0', '00')
0x58 (17L, 1L, 'DB 0x0', '00')
0x59 (17L, 1L, 'DB 0x0', '00')
0x5a (17L, 1L, 'DB 0x0', '00')
0x5b (17L, 1L, 'DB 0x0', '00')
0x5c (17L, 1L, 'DB 0x0', '00')
0x5d (17L, 1L, 'DB 0x0', '00')
0x5e (17L, 1L, 'DB 0x0', '00')
0x5f (17L, 1L, 'DB 0x0', '00')
0x60 (17L, 1L, 'DB 0x0', '00')
0x61 (17L, 1L, 'DB 0x0', '00')
0x62 (16L, 2L, 'BOUND EAX, [EAX]', '6200')
0x63 (16L, 2L, 'ARPL [EAX], AX', '6300')
0x64 (17L, 1L, 'DB 0x0', '00')
0x65 (17L, 1L, 'DB 0x0', '00')
0x66 (17L, 1L, 'DB 0x0', '00')
0x67 (17L, 1L, 'DB 0x0', '00')
0x68 (17L, 1L, 'DB 0x0', '00')
0x69 (17L, 1L, 'DB 0x0', '00')
0x6a (16L, 2L, 'PUSH 0x0', '6a00')
0x6b (17L, 1L, 'DB 0x0', '00')
0x6c (17L, 1L, 'DB 0x0', '00')
0x6d (17L, 1L, 'DB 0x0', '00')
0x6e (17L, 1L, 'DB 0x0', '00')
0x6f (17L, 1L, 'DB 0x0', '00')
0x70 (16L, 2L, 'JO 0x12', '7000')
0x71 (16L, 2L, 'JNO 0x12', '7100')
0x72 (16L, 2L, 'JB 0x12', '7200')
0x73 (16L, 2L, 'JAE 0x12', '7300')
0x74 (16L, 2L, 'JZ 0x12', '7400')
0x75 (16L, 2L, 'JNZ 0x12', '7500')
0x76 (16L, 2L, 'JBE 0x12', '7600')
0x77 (16L, 2L, 'JA 0x12', '7700')
0x78 (16L, 2L, 'JS 0x12', '7800')
0x79 (16L, 2L, 'JNS 0x12', '7900')
0x7a (16L, 2L, 'JP 0x12', '7a00')
0x7b (16L, 2L, 'JNP 0x12', '7b00')
0x7c (16L, 2L, 'JL 0x12', '7c00')
0x7d (16L, 2L, 'JGE 0x12', '7d00')
0x7e (16L, 2L, 'JLE 0x12', '7e00')
0x7f (16L, 2L, 'JG 0x12', '7f00')
0x80 (17L, 1L, 'DB 0x0', '00')
0x81 (17L, 1L, 'DB 0x0', '00')
0x82 (17L, 1L, 'DB 0x0', '00')
0x83 (17L, 1L, 'DB 0x0', '00')
0x84 (16L, 2L, 'TEST [EAX], AL', '8400')
0x85 (16L, 2L, 'TEST [EAX], EAX', '8500')
0x86 (16L, 2L, 'XCHG [EAX], AL', '8600')
0x87 (16L, 2L, 'XCHG [EAX], EAX', '8700')
0x88 (16L, 2L, 'MOV [EAX], AL', '8800')
0x89 (16L, 2L, 'MOV [EAX], EAX', '8900')
0x8a (16L, 2L, 'MOV AL, [EAX]', '8a00')
0x8b (16L, 2L, 'MOV EAX, [EAX]', '8b00')
0x8c (16L, 2L, 'MOV [EAX], ES', '8c00')
0x8d (16L, 2L, 'LEA EAX, [EAX]', '8d00')
0x8e (16L, 2L, 'MOV ES, [EAX]', '8e00')
0x8f (16L, 2L, 'POP DWORD [EAX]', '8f00')
0x90 (17L, 1L, 'DB 0x0', '00')
0x91 (17L, 1L, 'DB 0x0', '00')
0x92 (17L, 1L, 'DB 0x0', '00')
0x93 (17L, 1L, 'DB 0x0', '00')
0x94 (17L, 1L, 'DB 0x0', '00')
0x95 (17L, 1L, 'DB 0x0', '00')
0x96 (17L, 1L, 'DB 0x0', '00')
0x97 (17L, 1L, 'DB 0x0', '00')
0x98 (17L, 1L, 'DB 0x0', '00')
0x99 (17L, 1L, 'DB 0x0', '00')
0x9a (17L, 1L, 'DB 0x0', '00')
0x9b (17L, 1L, 'DB 0x0', '00')
0x9c (17L, 1L, 'DB 0x0', '00')
0x9d (17L, 1L, 'DB 0x0', '00')
0x9e (17L, 1L, 'DB 0x0', '00')
0x9f (17L, 1L, 'DB 0x0', '00')
0xa0 (17L, 1L, 'DB 0x0', '00')
0xa1 (17L, 1L, 'DB 0x0', '00')
0xa2 (17L, 1L, 'DB 0x0', '00')
0xa3 (17L, 1L, 'DB 0x0', '00')
0xa4 (17L, 1L, 'DB 0x0', '00')
0xa5 (17L, 1L, 'DB 0x0', '00')
0xa6 (17L, 1L, 'DB 0x0', '00')
0xa7 (17L, 1L, 'DB 0x0', '00')
0xa8 (16L, 2L, 'TEST AL, 0x0', 'a800')
0xa9 (17L, 1L, 'DB 0x0', '00')
0xaa (17L, 1L, 'DB 0x0', '00')
0xab (17L, 1L, 'DB 0x0', '00')
0xac (17L, 1L, 'DB 0x0', '00')
0xad (17L, 1L, 'DB 0x0', '00')
0xae (17L, 1L, 'DB 0x0', '00')
0xaf (17L, 1L, 'DB 0x0', '00')
0xb0 (16L, 2L, 'MOV AL, 0x0', 'b000')
0xb1 (16L, 2L, 'MOV CL, 0x0', 'b100')
0xb2 (16L, 2L, 'MOV DL, 0x0', 'b200')
0xb3 (16L, 2L, 'MOV BL, 0x0', 'b300')
0xb4 (16L, 2L, 'MOV AH, 0x0', 'b400')
0xb5 (16L, 2L, 'MOV CH, 0x0', 'b500')
0xb6 (16L, 2L, 'MOV DH, 0x0', 'b600')
0xb7 (16L, 2L, 'MOV BH, 0x0', 'b700')
0xb8 (17L, 1L, 'DB 0x0', '00')
0xb9 (17L, 1L, 'DB 0x0', '00')
0xba (17L, 1L, 'DB 0x0', '00')
0xbb (17L, 1L, 'DB 0x0', '00')
0xbc (17L, 1L, 'DB 0x0', '00')
0xbd (17L, 1L, 'DB 0x0', '00')
0xbe (17L, 1L, 'DB 0x0', '00')
0xbf (17L, 1L, 'DB 0x0', '00')
0xc0 (17L, 1L, 'DB 0x0', '00')
0xc1 (17L, 1L, 'DB 0x0', '00')
0xc2 (17L, 1L, 'DB 0x0', '00')
0xc3 (17L, 1L, 'DB 0x0', '00')
0xc4 (16L, 2L, 'LES EAX, [EAX]', 'c400')
0xc5 (16L, 2L, 'LDS EAX, [EAX]', 'c500')
0xc6 (17L, 1L, 'DB 0x0', '00')
0xc7 (17L, 1L, 'DB 0x0', '00')
0xc8 (17L, 1L, 'DB 0x0', '00')
0xc9 (17L, 1L, 'DB 0x0', '00')
0xca (17L, 1L, 'DB 0x0', '00')
0xcb (17L, 1L, 'DB 0x0', '00')
0xcc (17L, 1L, 'DB 0x0', '00')
0xcd (16L, 2L, 'INT 0x0', 'cd00')
0xce (17L, 1L, 'DB 0x0', '00')
0xcf (17L, 1L, 'DB 0x0', '00')
0xd0 (16L, 2L, 'ROL BYTE [EAX], 0x1', 'd000')
0xd1 (16L, 2L, 'ROL DWORD [EAX], 0x1', 'd100')
0xd2 (16L, 2L, 'ROL [EAX], CL', 'd200')
0xd3 (16L, 2L, 'ROL [EAX], CL', 'd300')
0xd4 (16L, 2L, 'AAM 0x0', 'd400')
0xd5 (16L, 2L, 'AAD 0x0', 'd500')
0xd6 (17L, 1L, 'DB 0x0', '00')
0xd7 (17L, 1L, 'DB 0x0', '00')
0xd8 (16L, 2L, 'FADD DWORD [EAX]', 'd800')
0xd9 (16L, 2L, 'FLD DWORD [EAX]', 'd900')
0xda (16L, 2L, 'FIADD DWORD [EAX]', 'da00')
0xdb (16L, 2L, 'FILD DWORD [EAX]', 'db00')
0xdc (16L, 2L, 'FADD QWORD [EAX]', 'dc00')
0xdd (16L, 2L, 'FLD QWORD [EAX]', 'dd00')
0xde (16L, 2L, 'FIADD WORD [EAX]', 'de00')
0xdf (16L, 2L, 'FILD WORD [EAX]', 'df00')
0xe0 (16L, 2L, 'LOOPNZ 0x12', 'e000')
0xe1 (16L, 2L, 'LOOPZ 0x12', 'e100')
0xe2 (16L, 2L, 'LOOP 0x12', 'e200')
0xe3 (16L, 2L, 'JECXZ 0x12', 'e300')
0xe4 (16L, 2L, 'IN AL, 0x0', 'e400')
0xe5 (16L, 2L, 'IN EAX, 0x0', 'e500')
0xe6 (16L, 2L, 'OUT 0x0, AL', 'e600')
0xe7 (16L, 2L, 'OUT 0x0, EAX', 'e700')
0xe8 (17L, 1L, 'DB 0x0', '00')
0xe9 (17L, 1L, 'DB 0x0', '00')
0xea (17L, 1L, 'DB 0x0', '00')
0xeb (16L, 2L, 'JMP 0x12', 'eb00')
0xec (17L, 1L, 'DB 0x0', '00')
0xed (17L, 1L, 'DB 0x0', '00')
0xee (17L, 1L, 'DB 0x0', '00')
0xef (17L, 1L, 'DB 0x0', '00')
0xf0 (17L, 1L, 'DB 0x0', '00')
0xf1 (17L, 1L, 'DB 0x0', '00')
0xf2 (17L, 1L, 'DB 0x0', '00')
0xf3 (17L, 1L, 'DB 0x0', '00')
0xf4 (17L, 1L, 'DB 0x0', '00')
0xf5 (17L, 1L, 'DB 0x0', '00')
0xf6 (17L, 1L, 'DB 0x0', '00')
0xf7 (17L, 1L, 'DB 0x0', '00')
0xf8 (17L, 1L, 'DB 0x0', '00')
0xf9 (17L, 1L, 'DB 0x0', '00')
0xfa (17L, 1L, 'DB 0x0', '00')
0xfb (17L, 1L, 'DB 0x0', '00')
0xfc (17L, 1L, 'DB 0x0', '00')
0xfd (17L, 1L, 'DB 0x0', '00')
0xfe (16L, 2L, 'INC BYTE [EAX]', 'fe00')
0xff (16L, 2L, 'INC DWORD [EAX]', 'ff00')
보시다시피 스택도 이런식으로 밀 수가 있습니다.
이걸 활용할 요긴할 곳을 꼽자면..
cgi에서 프로그램을 실행할 때 argv형태로 넘겨주게 됩니다. 주소의 QUERY_STRING부분을요.