col

 

col

 

一、进入:

二、源码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 unsigned long hashcode = 0x21DD09EC;
 4 unsigned long check_password(const char* p){
 5     int * ip = (int*p);
 6     int i;
 7     int res = 0;
 8     for (i=0;i<5;i++){
 9         res += ip[i];
10     }
11     resturn res;
12 }
13 int main(int argc , char* argv[]){
14     if(argc<2){
15         printf("usage:%s [passcode]\n",argv[0]);
16         return 0;
17     }
18     if((argv[1])!=20){
19         printf("passcode length should be 20 bytes\n");
20         return 0;
21     }
22     if (hashcode == check_password(argv[1])){
23         system("/bin/cat flag");
24         return 0;
25     }
26     else
27         printf("wrong passcode .\n");
28     return 0;
29 }

 

三、审计: 

1、main
1)运行程序、输入数据
2)如果输入的数据必须是20个字节
strlen():计算字符串的程度
3)输入的数据经过check_password处理后 = 0x21DD09EC,才能获取flag
2、check_password
1)将输入函数的数据强制转换成int
2)读取转换后的数据,每读取4个,一起相加,最后返回。

 

四、利用:

1、利用思路:

要获取flag:
首先:输入的数据 = 0x21DD09EC
其次:输入的数据必须是20个字节
接着:需要经过check_password的5次处理
最后总结:分5次输入数据,使得5次输入的数据最后相加为0x21DD09EC。

2、利用代码:

 

from  pwn import * 
ssh_col = ssh(host="pwnable.kr",user="col",password="guest",port=2222)
print(ssh_col.connected())
exe = ssh_col.process(argv=['col','\x01' * 16 + "\xE8\x05\xD9\x1D"],executable='./col')
print(exe.recvall())

PS:最后的数据输入,采取了小端模式:

3、介绍:大端模式(Big_Endian)和小端模式(Little_Endian)

1)大端模式:高位字节排放在内存的低地址端,低位字节排放在内存的高地址端。

2)小端模式:地位字节排放在内存的低地址端,高位字节排放在内存的高地址端

3)采用小端模式,将后读取的字节数据首先放进去,到读取时候正好相反,达到所需的目的。

五、总结:

C语言零基础的,要开始学习C语言。

 

六、参考:

https://www.cnblogs.com/spd2016/p/5487718.html

http://www.mamicode.com/info-detail-1688803.html

猜你喜欢

转载自www.cnblogs.com/beiweisanshidu/p/10247056.html
col