Skip to content

Commit cf6e142

Browse files
carlospolopgitbook-bot
authored andcommitted
GitBook: [master] one page modified
1 parent f1743c7 commit cf6e142

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

macos/macos-security-and-privilege-escalation/inspecting-and-debugging-mac-os-apps.md

+64-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,70 @@ ktrace trace -s -S -t c -c ls | grep "ls("
3232

3333
### dtrace
3434

35+
It allows users access to applications at an extremely **low level** and provides a way for users to **trace** **programs** and even change their execution flow. Dtrace uses **probes** which are **placed throughout the kernel** and are at locations such as the beginning and end of system calls.
36+
37+
The available probes of dtrace can be obtained with:
38+
39+
```bash
40+
dtrace -l | head
41+
ID PROVIDER MODULE FUNCTION NAME
42+
1 dtrace BEGIN
43+
2 dtrace END
44+
3 dtrace ERROR
45+
43 profile profile-97
46+
44 profile profile-199
47+
```
48+
49+
The probe name consists of four parts: the provider, module, function, and name \(`fbt:mach_kernel:ptrace:entry`\). If you not specifies some part of the name, Dtrace will apply that part as a wildcard.
50+
51+
A more detailed explanation and more examples can be found in [https://illumos.org/books/dtrace/chp-intro.html](https://illumos.org/books/dtrace/chp-intro.html)
52+
53+
#### Examples
54+
55+
* In line
56+
57+
```bash
58+
#Count the number of syscalls of each running process
59+
sudo dtrace -n 'syscall:::entry {@[execname] = count()}'
60+
```
61+
62+
* script
63+
64+
```bash
65+
syscall:::entry
66+
/pid == $1/
67+
{
68+
}
69+
70+
#Log every syscall of a PID
71+
sudo dtrace -s script.d 1234
72+
```
73+
3574
```bash
36-
sudo dtrace -n 'syscall:::entry {@[execname] = count()}' #Count the number of syscalls of each running process
75+
syscall::open:entry
76+
{
77+
printf("%s(%s)", probefunc, copyinstr(arg0));
78+
}
79+
syscall::close:entry
80+
{
81+
printf("%s(%d)\n", probefunc, arg0);
82+
}
83+
84+
#Log files opened and closed by a process
85+
sudo dtrace -s b.d -c "cat /etc/hosts"
86+
```
87+
88+
```bash
89+
syscall:::entry
90+
{
91+
;
92+
}
93+
syscall:::return
94+
{
95+
printf("=%d\n", arg1);
96+
}
97+
98+
#Log sys calls with values
99+
sudo dtrace -s syscalls_info.d -c "cat /etc/hosts"
37100
```
38101

0 commit comments

Comments
 (0)