Skip to content

Commit

Permalink
applied markdownlint
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Jul 31, 2023
1 parent e5edb71 commit 7a75fc7
Show file tree
Hide file tree
Showing 40 changed files with 147 additions and 114 deletions.
32 changes: 16 additions & 16 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ register_external_command(NewCommand())
```

Loading it in `GEF` is as easy as

```
gef➤ source /path/to/newcmd.py
[+] Loading 'NewCommand'
Expand Down Expand Up @@ -61,15 +62,17 @@ We make GEF aware of this new command by registering it in the `__main__` sectio
invoking the global function `register_external_command()`.

Now you have a new GEF command which you can load, either from cli:

```bash
gef➤ source /path/to/newcmd.py
```

or add to your `~/.gdbinit`:

```bash
$ echo source /path/to/newcmd.py >> ~/.gdbinit
echo source /path/to/newcmd.py >> ~/.gdbinit
```


## Customizing context panes

Sometimes you want something similar to a command to run on each break-like event and display itself
Expand Down Expand Up @@ -119,20 +122,22 @@ gef➤ pi help(Architecture)
or even from outside GDB:

```bash
$ gdb -q -ex 'pi help(hexdump)' -ex quit
gdb -q -ex 'pi help(hexdump)' -ex quit
```

The GEF API aims to provide a simpler and more Pythonic approach to GDB's.

Some basic examples:
- read the memory
* read the memory

```python
gef ➤ pi print(hexdump( gef.memory.read(parse_address("$pc"), length=0x20 )))
0x0000000000000000 f3 0f 1e fa 31 ed 49 89 d1 5e 48 89 e2 48 83 e4 ....1.I..^H..H..
0x0000000000000010 f0 50 54 4c 8d 05 66 0d 01 00 48 8d 0d ef 0c 01 .PTL..f...H.....
```

- get access to the memory layout
* get access to the memory layout

```
gef ➤ pi print('\n'.join([ f"{x.page_start:#x} -> {x.page_end:#x}" for x in gef.memory.maps]))
0x555555554000 -> 0x555555558000
Expand All @@ -148,18 +153,15 @@ gef ➤ pi print('\n'.join([ f"{x.page_start:#x} -> {x.page_end:#x}" for x in ge
[...]
```


The API also offers a number of decorators to simplify the creation of new/existing commands, such as:
- `@only_if_gdb_running` to execute only if a GDB session is running.
- `@only_if_gdb_target_local` to check if the target is local i.e. not debugging using GDB `remote`.
- and many more...

* `@only_if_gdb_running` to execute only if a GDB session is running.
* `@only_if_gdb_target_local` to check if the target is local i.e. not debugging using GDB `remote`.
* and many more...

### Reference

For a complete reference of the API offered by GEF, visit [`docs/api/gef.md`](api/gef.md).


### Parsing command arguments

```python
Expand All @@ -179,12 +181,10 @@ using a type of `tuple` or `list` for the default value. `parse_arguments` will
of what to expect based on the first default value of the iterable, so make sure it's not empty. For
instance:


```python
@parse_arguments( {"instructions": ["nop", "int3", "hlt"], }, {"--arch": "x64", } )
```


Argument flags are also supported, allowing to write simpler version of the flag such as

```python
Expand Down Expand Up @@ -227,11 +227,11 @@ Sometimes architectures can more precisely determine whether they apply to the c
looking at the architecture determined by gdb. For these cases the custom architecture may implement
the `supports_gdb_arch()` static function to signal that they should be used instead of the default.
The function receives only one argument:
- `gdb_str` (of type `str`) which is the architecture name as reported by GDB.
* `gdb_str` (of type `str`) which is the architecture name as reported by GDB.

The function **must** return:
- `True` if the current `Architecture` class supports the target binary; `False` otherwise.
- `None` to simply ignore this check and let GEF try to determine the architecture.
* `True` if the current `Architecture` class supports the target binary; `False` otherwise.
* `None` to simply ignore this check and let GEF try to determine the architecture.

One example is the ARM Cortex-M architecture which in some cases should be used over the generic ARM
one:
Expand Down
3 changes: 3 additions & 0 deletions docs/commands/aslr.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
Easily check, enable or disable ASLR on the debugged binary.

Check the status:

```
gef➤ aslr
ASLR is currently disabled
```

Activate ASLR:

```
gef➤ aslr on
[+] Enabling ASLR
Expand All @@ -17,6 +19,7 @@ ASLR is currently enabled
```

De-activate ASLR:

```
gef➤ aslr off
[+] Disabling ASLR
Expand Down
1 change: 1 addition & 0 deletions docs/commands/canary.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ If the currently debugged process was compiled with the Smash Stack Protector (S
canary. This makes it convenient to avoid manually searching for this value in memory.

The command `canary` does not take any arguments.

```
gef➤ canary
```
Expand Down
3 changes: 2 additions & 1 deletion docs/commands/checksec.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The `checksec` command is inspired from [`checksec.sh`](https://www.trapkit.de/t
It provides a convenient way to determine which security protections are enabled in a binary.

You can use the command on the currently debugged process:

```
gef➤ checksec
[+] checksec for '/vagrant/test-bin'
Expand All @@ -19,5 +20,5 @@ Full RelRO: No
Or specify directly the binary to check, for example:

```bash
$ gdb -ex "checksec ./tests/test-x86"
gdb -ex "checksec ./tests/test-x86"
```
6 changes: 6 additions & 0 deletions docs/commands/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ specified via the `GEF_RC` environment variable. In addition, `gef` can also be
runtime with the `gef config` command.

To view all settings for all commands loaded:

```
gef➤ gef config
```

![gef-config](https://i.imgur.com/bd2ZqsU.png)

Or to get one setting value:

```
gef➤ gef config pcustom.struct_path
```

Of course you can edit the values. For example, if you want the screen to be cleared before
displaying the current context when reaching a breakpoing:

```
gef➤ gef config context.clear_screen 1
```

To save the current settings for `GEF` to the file system to have those options persist across all
your future `GEF` sessions, simply run:

```
gef➤ gef save
[+] Configuration saved to '/home/vagrant/.gef.rc'
Expand All @@ -32,6 +37,7 @@ Upon startup, if `$GEF_RC` points to an existing file, or otherwise if `${HOME}/
`gef` will automatically load its values.

To reload the settings during the session, just run:

```
gef➤ gef restore
[+] Configuration from '/home/hugsy/.gef.rc' restored
Expand Down
19 changes: 17 additions & 2 deletions docs/commands/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

![gef-context](https://i.imgur.com/aZiG8Yb.png)


`gef` (not unlike `PEDA` or `fG! famous gdbinit`) provides comprehensive context menu when hitting a
breakpoint.

Expand Down Expand Up @@ -54,6 +53,7 @@ just omit it.
```
gef➤ gef config context.layout "-legend regs stack code args -source -threads -trace extra memory"
```

This configuration will not display the `legend`, `source`, `threads`, and `trace` sections.

The `memory` pane will display the content of all locations specified by the
Expand All @@ -80,12 +80,14 @@ The size of most sections are also customizable:

To have the stack displayed with the largest stack addresses on top (i.e., grow the stack downward),
enable the following setting:

```
gef➤ gef config context.grow_stack_down True
```

If the saved instruction pointer is not within the portion of the stack being displayed, then a
section is created that includes the saved ip and depending on the architecture the frame pointer.

```
0x00007fffffffc9e8│+0x00: 0x00007ffff7a2d830 → <__main+240> mov edi, eax ($current_frame_savedip)
0x00007fffffffc9e0│+0x00: 0x00000000004008c0 → <__init+0> push r15 ← $rbp
Expand All @@ -108,80 +110,93 @@ setting `context.redirect` variable to have the context sent to another section.
To do so, select the TTY/file/socket/etc. you want the context redirected to with `gef config`.

Enter the command `tty` in the prompt:

```
$ tty
/dev/pts/0
```

Then tell `gef` about it!

```
gef➤ gef config context.redirect /dev/pts/0
```

Enjoy:
![gef-context-redirect-section](https://i.imgur.com/sWlX37q.png)


To go back to normal, remove the value:

```
gef➤ gef config context.redirect ""
```

### Display individual sections ###

You can display a single section by specifying it as an argument:

```
gef➤ context regs
```

Multiple sections can be provided, even if they are not part of the current layout:

```
gef➤ context regs stack
```

### Examples ###

* Display the code section first, then register, and stack, hiding everything else:

```
gef➤ gef config context.layout "code regs stack"
```

* Stop showing the context sections when breaking:

```
gef➤ gef config context.enable 0
```

* Clear the screen before showing the context sections when breaking:

```
gef➤ gef config context.clear_screen 1
```

* Don't dereference the registers in the `regs` section (more compact):

```
gef➤ gef config context.show_registers_raw 1
```

* Number of bytes of opcodes to display next to the disassembly.

```
gef➤ gef config context.show_opcodes_size 4
```

* Don't 'peek' into the start of functions that are called.

```
gef➤ gef config context.peek_calls False
```

* Hide specific registers from the registers view.

```
gef➤ gef config context.ignore_registers "$cs $ds $gs"
```

* Hide the extra pc context info from the source code view.

```
gef➤ gef config context.show_source_code_variable_values 0
```

* Show better definitions for call to libc functions.

```
gef➤ gef config context.libc_args True
gef➤ gef config context.libc_args_path /path/to/gef-extras/libc_args
Expand Down
3 changes: 2 additions & 1 deletion docs/commands/dereference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dereference (by default, `$sp`), the number of consecutive addresses to derefere

```
gef➤ dereference
0x00007fffffffdec0│+0x0000: 0x00007ffff7ffe190 → 0x0000555555554000 → jg 0x555555554047 ← $rsp, $r13
0x00007fffffffdec0│+0x0000: 0x00007ffff7ffe190 → 0x0000555555554000 → jg 0x555555554047 ← $rsp, $r13
0x00007fffffffdec8│+0x0008: 0x00007ffff7ffe730 → 0x00007ffff7fd3000 → 0x00010102464c457f
0x00007fffffffded0│+0x0010: 0x00007ffff7faa000 → 0x00007ffff7de9000 → 0x03010102464c457f
0x00007fffffffded8│+0x0018: 0x00007ffff7ffd9f0 → 0x00007ffff7fd5000 → 0x00010102464c457f
Expand Down Expand Up @@ -70,6 +70,7 @@ gef➤ dereference $sp -l 7 -r $rbp

Just like with `x`, you can pass a negative number of addresses to dereference, to examine memory
backwards from the start address:

```
gef➤ dereference $sp -l 3
0x00007fffffffcf90│+0x0010: 0x00007ffff7f5aaa0 → 0x0000000000000000
Expand Down
3 changes: 3 additions & 0 deletions docs/commands/edit-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ the flag register for the architectures that support it. Without argument, the c
return a human-friendly display of the register flags.

One or many arguments can be provided, following the syntax below:

```
gef➤ flags [(+|-|~)FLAGNAME ...]
```

Where `FLAGNAME` is the name of the flag (case insensitive), and `+|-|~` indicates the action on
whether to set, unset, or toggle the flag.

Expand All @@ -17,4 +19,5 @@ instruction), but we want to have the Carry flag set, simply go with:
```
gef➤ flags -ZERO +CARRY
```

![flags](https://i.imgur.com/ro7iC5m.png)
2 changes: 1 addition & 1 deletion docs/commands/format-string-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gef➤ fmtstr-helper
```

Then start the binary execution.

```
gef➤ r
```
Expand All @@ -28,4 +29,3 @@ If a potentially insecure entry is found, the breakpoint will trigger, stop the
display the reason for trigger and the associated context.

![fmtstr-helper-example](https://i.imgur.com/INU3KGn.png)

6 changes: 3 additions & 3 deletions docs/commands/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ These functions can be used as arguments to other commands to dynamically calcul

```
gef➤ deref -l 4 $_heap()
0x0000000000602000│+0x00: 0x0000000000000000 ← $r8
0x0000000000602000│+0x00: 0x0000000000000000 ← $r8
0x0000000000602008│+0x08: 0x0000000000000021 ("!"?)
0x0000000000602010│+0x10: 0x0000000000000000 ← $rax, $rdx
0x0000000000602010│+0x10: 0x0000000000000000 ← $rax, $rdx
0x0000000000602018│+0x18: 0x0000000000000000
gef➤ deref -l 4 $_heap(0x20)
0x0000000000602020│+0x00: 0x0000000000000000 ← $rsi
0x0000000000602020│+0x00: 0x0000000000000000 ← $rsi
0x0000000000602028│+0x08: 0x0000000000020fe1
0x0000000000602030│+0x10: 0x0000000000000000
0x0000000000602038│+0x18: 0x0000000000000000
Expand Down
Loading

0 comments on commit 7a75fc7

Please sign in to comment.