or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
IT Security 2 (Ch7~Ch8)
Chapter 7: Buffer Overflows and other Memory Corruptions
buffer會overwriting接下來的資料
增加instruction的byte長度給EIP
在 function calls 暫時儲存的空間
stack frame儲存
恢復Extended stack pointer,指向stack的尾端
恢復EIP,指向下個instruction
在每個function call時產生
Stack Example
複寫鄰近的stack區塊
eg.
execve("/bin/sh")
若victim program是
setuid root
則可得到 root shelleg.
system()
,exec()
execve("/bin/sh")
system("command.exe")
execve()
)strcpy
strcat
gets
scanf
printf
strncpy
只有最多
n
個字被複製strncat
首
n
個*src
才能被複製到*dest
中for (i=0; i<=512; i++)
會copy 513個字元
Buf
overflow,則會蓋住vtable
ptr
指向的vtable
的位址會變成overflow的data (eg. shell code)Dynamic Memory Management in C
malloc(size_t n)
n
bytes 並回傳一個指標free(void *p)
p
指標指向的memory spacemalloc
/delete
)Variable Arguments in C
printf
可以有可變的輸入數量printf("hello, world");
printf("length of '%s' = %d", str, str.length());
va_start
,va_arg
,va_end
printf("foo = %d", foo);
char buf[123]="hello world; printf(buf);
(正確用法:
printf("%s", buf);
)%
,則原本的stack pointer會以為是argument%n
: 印出的字元數量RET
會指向attack code
,printf(buffer)
會寫入attackString
的number of characters 到RET
中buf
overflow 的話會改變 Canary\0
,EOF
就不會被
strcpy
就不會繼續copybuf
和pointer
旁邊更降低performancestrcpy
複寫pointer,指向RETstrcpy
可以複寫而且避開 Canarystrcpy
|frame-pointer – dest| > strlen(src)
此保障就無法阻止control transfer
預測 return address
malloc
跟把standard library routines放在heapChapter 8: Access Control
儲存Access Control Matrix的每個 Column
每個list: \(\text{I=\{(s,r):s}\in S\text{,r}\subset R\text{\}}\)
example
\(\text{acl(file1)={(process 1, {read,write,own}),(process 2,{append})}}\)
owner, group, others
rwx = read(4), write(2), execute(1)
d
: directory-
: notchmod 754 filename
對
filename
指定rwx r-x r--
權限set-user-ID
,否則為新的 process的user IDeuid
euid
但存在suid
setuid
euid == 0
,設定ruid
及euid
為特定值euid
為ruid
\[\text{setuid(s)}=\begin{cases}\text{euid = ruid = s, if euid == 0}\\ \text{euid = s, otherwise}\end{cases}\]
seteuid
in System Veuid
為任意user IDeuid
為ruid
或suid
\[\text{seteuid(s)}=\begin{cases}\text{euid = s (any user ID), if euid == 0}\\ \text{euid = ruid / suid, otherwise}\end{cases}\]
setruid
in BSDruid
和euid
可以被設為任意user ID\[\text{setruid(s)}=\begin{cases}\text{euid = ruid = s (any user ID), if euid == 0}\\ \text{euid = ruid / ruid = euid, otherwise}\end{cases}\]
setresuid
,可以設定三種user IDsuid==euid==0
setuid
只允許dropeuid
不允許dropsuid
most closely matching one(最多符合)允許,則取得權限
\(\text{RBAC}_0\)
\(\text{RBAC}_1\)
\(\text{RBAC}_2\)
\(\text{RBAC}_3\)