Skip to content

Commit 500b2d4

Browse files
zweilosecgitbook-bot
authored andcommitted
GitBook: [master] 61 pages modified
1 parent 72f3a52 commit 500b2d4

File tree

3 files changed

+153
-139
lines changed

3 files changed

+153
-139
lines changed

linux-1/linux-basics.md

+108-85
Original file line numberDiff line numberDiff line change
@@ -109,30 +109,30 @@ TODO: Add screenshots/code examples for each command; put commands in tables; cl
109109

110110
### Special Symbols
111111

112-
| `Symbol` | Purpose |
113-
| :--- | :--- |
114-
| `|` | Send the output of one command to another. |
115-
| `>` | Redirect output to a file. |
116-
| `<` | Redirect input from a file. |
117-
| `>>` | Append output to an existing file. |
118-
| `/` | Separator used in path names. |
119-
| `\` | Used to escape characters and to send multi-line commands. |
120-
| `.` | Current directory. |
121-
| `..` | Parent directory. |
122-
| `$$` | displays the process ID of the current shell instance. |
123-
| `&` | Process command in the background \(and give control of the terminal back\). |
124-
| `&&` | Run the next command only if the previous completed successfully. |
125-
| `*` | Match any number of characters in file name. |
126-
| `?` | Match any single character in file name. |
127-
| `[ ]` | Match any one of the enclosed characters in file name. |
128-
| `;` | Run commands in sequence, regardless if the previous succeeded. |
129-
| `( )` | Group commands. |
130-
| `{ }` | Used to feed multiple parameters to a single command. Separate parameters by `,` |
131-
| `!` | Followed by a digit will repeat the command from the history file that corresponds. |
132-
| `!!` | Repeat the previous command. |
133-
| `0` | Shortcut that stands for Standard Input \(STDIN\) |
134-
| `1` | Shortcut that stands for Standard Output \(STDOUT\) |
135-
| `2` | Shortcut that stands for Standard Error \(STDERR\) |
112+
| `Symbol` | Purpose | |
113+
| :--- | :--- | :--- |
114+
| \` | \` | Send the output of one command to another. |
115+
| `>` | Redirect output to a file. | |
116+
| `<` | Redirect input from a file. | |
117+
| `>>` | Append output to an existing file. | |
118+
| `/` | Separator used in path names. | |
119+
| `\` | Used to escape characters and to send multi-line commands. | |
120+
| `.` | Current directory. | |
121+
| `..` | Parent directory. | |
122+
| `$$` | displays the process ID of the current shell instance. | |
123+
| `&` | Process command in the background \(and give control of the terminal back\). | |
124+
| `&&` | Run the next command only if the previous completed successfully. | |
125+
| `*` | Match any number of characters in file name. | |
126+
| `?` | Match any single character in file name. | |
127+
| `[ ]` | Match any one of the enclosed characters in file name. | |
128+
| `;` | Run commands in sequence, regardless if the previous succeeded. | |
129+
| `( )` | Group commands. | |
130+
| `{ }` | Used to feed multiple parameters to a single command. Separate parameters by `,` | |
131+
| `!` | Followed by a digit will repeat the command from the history file that corresponds. | |
132+
| `!!` | Repeat the previous command. | |
133+
| `0` | Shortcut that stands for Standard Input \(STDIN\) | |
134+
| `1` | Shortcut that stands for Standard Output \(STDOUT\) | |
135+
| `2` | Shortcut that stands for Standard Error \(STDERR\) | |
136136

137137
### Recover an unresponsive terminal
138138

@@ -277,9 +277,9 @@ Everything in Linux is a file, even directories and devices. Directories have so
277277
| `touch $fileName` | Create a new blank file with this name |
278278
| `cp $file [/path/to/]$newFile` | Copy file from one location to another. If no location is specified, creates the copy in the same directory. |
279279
| `mv $file [/path/to/]$newFile` | Move file from one location to another. If no location is specified, renames the file in same directory \(removes the old file\). |
280-
| `rm $file` | Removes \(deletes\) a file. |
280+
| `rm $file` | Removes \(deletes\) a file. |
281281
| `rm *` | Removes \(deletes\) all files in the directory. |
282-
| `rm -rf *` | Recursively deletes all files in the directory and all subdirectories and files. Will not prompt for approval with `-f`. |
282+
| `rm -rf *` | Recursively deletes all files in the directory and all subdirectories and files. Will not prompt for approval with `-f`. |
283283
| `mkdir [/path/to/]$dir` | Makes a new empty directory |
284284
| `mkdir -p test/{test1,test2}` | The `-p` flag creates multiple directories at once. In this example we use brace expansion to create `test/` and 2 subdirectories under it. |
285285
| `rmdir $dir` | Deletes an empty directory |
@@ -293,7 +293,7 @@ Everything in Linux is a file, even directories and devices. Directories have so
293293
| `wc` | Counts the lines, words, and bytes in a file. `-l` will count only lines, `-m` will count only characters, `-c` will count only bytes, `-w` will count only words |
294294
| `awk` | A programming language for text processing. Can do many many things. |
295295
| `sed` | Performs text editing on a stream of text. Useful for replacing text in a file and much more |
296-
| `cut` | Extract a section of text. **`-f`** selects the field, **`-d`** sets the delimiter. |
296+
| `cut` | Extract a section of text. **`-f`** selects the field, **`-d`** sets the delimiter. |
297297
| `sort` | |
298298
| `uniq` | |
299299

@@ -305,118 +305,141 @@ cat > $fileName
305305

306306
### File Permissions
307307

308-
> TODO: Add more information about Linux file permissions \(both `octal` and `ugo-rwx` formats\); Add information about `chmod` and `chown` commands; Add descriptions and examples \(issue [\#8](https://github.com/zweilosec/Infosec-Notes/issues/8)\)
308+
The permissions for a file \(for example, viewed with the `ls -l` command\) are typically written as:
309+
310+
```bash
311+
-rwxrwxrwx owner group [metadata] $filename
312+
```
313+
314+
**`r`** = read **`w`** = write **`x`** = execute
309315

310-
File permissions in linux can be expressed in two formats, the rwx and the octal notation.
316+
Breaking down this format gives us four parts:
311317

312-
#### rwx notation
318+
1. The first character tells if it is a file or a directory. if it is a **`-`** \(hyphen\) then it is a file. However if the first character is a **`d`**, then the file is a directory. \(Remember, technically everything in Linux is a file, even directories\).
319+
2. The next three characters specify the permissions of the owner of the file.
320+
3. The following three characters specify the permissions of the group that owns the file.
321+
4. The final three characters specify the permissions of all other users.
313322

314-
r = read\
315-
w = write\
316-
x = execute
323+
The permissions `-rwxrwxrwx` mean that the anyone can read, write and execute the file.
317324

318-
In linux the if the permission of a file would be :
325+
In the above example, the owner, group, and everyone permissions are all `rwx`; hence anyone can read, write, and execute this file.
319326

320-
`-rwxrwxrwx`
327+
#### The chmod command
321328

322-
Then that would mean that the anyone can read, write and execute the file. Breaking down this format into four parts :
323-
1. The first character would tell if it is a file or a directory, if it is a '-' (hyphen) then it would mean it is a file, but if it is 'd', then
324-
it would mean that it is a directory.
325-
2. The next three characters specify the permission of the owner of the file.
326-
3. The next three character specify the permissions of the group.
327-
4. The last three character would specify the characters of others.
329+
The `chmod` command is used to set the permissions on a file. This is usually expressed in one of two different formats, ugoa+rwx and octal notation. The command is used as follows:
328330

329-
In the above example all of them had rwx assigned to them, hence anyone could read, write and execute this file.
331+
```bash
332+
chmod [permissions] $file
333+
```
330334

331335
#### Octal notation
332336

333-
In the octal notation, the permissions are assigned using octal digits.
337+
In octal notation, the permissions are assigned using triple octal \(base8\) digits. The first digit is the cumulative permissions for the owner, the second for the group, and the third for everyone else.
334338

335-
| Permissions | binary notation | octal notation | Description |
336-
| :--- | :--- | :--- | :-- |
337-
| --- | 000 | 0 | No permission |
338-
| --x | 001 | 1 | Execute permission only |
339-
| -w- | 010 | 2 | Write permission only |
340-
| -wx | 011 | 3 | Write and execute |
341-
| r-- | 100 | 4 | Read permission only |
342-
| r-x | 101 | 5 | Read and execute permission |
343-
| rw- | 110 | 6 | Read and write permission |
344-
| rwx | 111 | 7 | Read, write and execute |
339+
| Permissions | Binary notation | Octal notation | Description |
340+
| :--- | :--- | :--- | :--- |
341+
| `---` | 000 | 0 | No permissions |
342+
| `--x` | 001 | 1 | Execute permission only |
343+
| `-w-` | 010 | 2 | Write permission only |
344+
| `-wx` | 011 | 3 | Write and execute |
345+
| `r--` | 100 | 4 | Read permission only |
346+
| `r-x` | 101 | 5 | Read and execute permission |
347+
| `rw-` | 110 | 6 | Read and write permission |
348+
| `rwx` | 111 | 7 | Read, write and execute |
345349

346350
From the above table we can easily derive :
347351

348-
Read = 4\
349-
Write = 2\
350-
Execute = 1
352+
```bash
353+
Read = 4 Write = 2 Execute = 1
354+
```
351355

352-
Therefore if you would want to give a read and write, it would be 6 (4+2=6).
356+
Therefore, if you want to give only the owner read and write permissions, they would be assigned `600` \(4+2=6\).
353357

354-
Now taking the same above example of -rwxrwxrwx :
355-
In order to assign a file this permission using the octal notation and chmod
356-
it would be :
358+
Taking the same example from above, to assign the permissions `-rwxrwxrwx` the command would be:
357359

358-
`chmod 777 file`
360+
```bash
361+
chmod 777 $file
362+
```
359363

360-
The first 7 would mean for the owner (4+2+1), the second 7 for the group and the third one for others.
364+
That is: read \(4\), write \(2\), and execute \(1\) permissions for the owner, group, and all others.
361365

362-
u = user\
363-
g = group\
364-
o = others\
365-
a = u+g+o (all)
366+
#### ugoa+rwx notation
366367

367-
You can also give permissions using this method :
368+
In this notation format, there are three main components:
368369

369-
`chmod a+w file`
370+
1. _Who._ The users to modify permissions for: `u` = user \(owner\), `g` = group, `o` = others, and finally `a` = u+g+o \(all\).
371+
2. _What._ The modifier: `=` to set permissions, `+` for adding permissions, `-` for removing permissions.
372+
3. _Which._ The permissions to set, add, or remove: one or more of `rwx` as above.
370373

371-
The above example would give write permissions to everyone.
374+
As you can see, this notations allows for easier and more explicit control over exactly which permissions are given to whom.
372375

373-
`chmod a-x file`
376+
Examples:
374377

375-
The above example would remove execute permissions for everyone.
378+
To give all users the write permission:
379+
380+
```bash
381+
chmod a+w $file
382+
```
376383

377-
#### Advanced permissions
384+
To remove write and execute permissions from the 'other' group:
385+
386+
```bash
387+
chmod o-wx $file
388+
```
389+
390+
These permission changes can also be chained by adding a comma between the permission changes.
391+
392+
To add read/write permissions for the file owner and group, while making it read only for everyone else:
393+
394+
```bash
395+
chmod ug+rw,o=r $file
396+
```
397+
398+
#### Advanced permissions \(TODO: Finish cleaning this up. Add descriptions of SUID/GUID\)
378399

379400
Other than just read and write, you can also set some other permissions like SUID and GUID.
380401

381402
`chmod 4000 file`
382403

383404
`chmod +s file`
384405

385-
Both the above examples would add the setuid bit to the file.
406+
Both the above examples would add the `setuid` bit to the file.
386407

387408
`chmod 2000 file`
388409

389410
`chmod +g file`
390411

391-
Both the above examples would add the getuid bit to the file
412+
Both the above examples would add the `getuid` bit to the file.
413+
414+
#### The sticky bit
415+
416+
[https://en.wikipedia.org/wiki/Sticky\_bit](https://en.wikipedia.org/wiki/Sticky_bit) &lt;- pull more information from here and add
392417

393-
The sticky bit is added to folders mainly in order to prevent anyone else from deleting the folder.
394-
or any of it's contents. It is represented by a 't' at the end. When a sticky bit is set, nobody other than
395-
the owner or the root can delete the folder or the file.
418+
The "sticky bit" is added to folders in order to prevent anyone else from deleting the folder or any of its contents. It is represented by a `t` at the end of the permissions `d--r--r--rt`. When a sticky bit is set, nobody other than the owner or the root can delete the folder or the file.
396419

397420
`chmod 1000 folder`
398421

399422
`chmod +t folder`
400423

401424
Both the above examples set the sticky bit to the folders
402425

403-
Examples:
404-
`chmod 1744 file`
426+
Examples: `chmod 1744 file`
405427

406428
This would set the sticky bit, give all permissions to the owner and only read permission to the group and others
407429

408430
`chmod 0600 file`
409431

410432
This would only give the owner read and write permission, but not execute permission.
411433

412-
#### chown command
434+
#### The chown command
413435

414-
The chown command can be used to change the owner of a file or a directory.
436+
The `chown` command can be used to change the owner of a file or a directory.
415437

416-
`chown $user $group $file`
417-
418-
The above command would change the owner of the file from root to $user and also the group to $group
438+
```bash
439+
chown $user $group $file
440+
```
419441

442+
The above command would change the owner of the file to `$user` and also the group to `$group`.
420443

421444
### File compression and encryption
422445

@@ -506,7 +529,7 @@ TODO: add more information on mounting and using network shares \(issue [\#10](h
506529
| `apt show $package` | Show details about the specified package |
507530
| `sudo apt install $package` | Installs the specified package \(and any dependencies\). |
508531
| `apt remove --purge $package` | Uninstalls the specified package |
509-
| `dpkg -i $deb_file` | Installs the specified `.deb` package file \(Does not install dependencies\). |
532+
| `dpkg -i $deb_file` | Installs the specified `.deb` package file \(Does not install dependencies\). |
510533
| `alien $file.rpm` | Convert rpm to Debian packages |
511534

512535
## Users and Groups

web/dns.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% hint style="success" %}
44
Hack Responsibly.
55

6-
Always ensure you have **explicit** permission to access any computer system **before** using any of the techniques contained in these documents. You accept full responsibility for your actions by applying any knowledge gained here.
6+
Always ensure you have **explicit** permission to access any computer system **before** using any of the techniques contained in these documents. You accept full responsibility for your actions by applying any knowledge gained here.
77
{% endhint %}
88

99
## Hosts File
@@ -36,7 +36,7 @@ DNS offers a variety of information about public \(and sometimes private!\) orga
3636

3737
zonetransfer.me \([https://digi.ninja/projects/zonetransferme.php](https://digi.ninja/projects/zonetransferme.php)\)
3838

39-
A public training site for testing and learning about DNS. Uses the following two name servers:
39+
A public training site for testing and learning about DNS. Uses the following two name servers:
4040

4141
* nsztm1.digi.ninja
4242
* nsztm2.digi.ninja
@@ -263,19 +263,17 @@ dig -f file.txt [options]
263263
dnsenum 10.11.1.111
264264
```
265265

266-
267266
### DNS reverse lookup
268267

269268
#### Using powershell
270269

271-
```
270+
```text
272271
$ComputerIPAddress = "10.10.10.10"
273-
[System.Net.Dns]::GetHostEntry($ComputerIPAddress).HostName
274272
```
275273

276-
#### Using dnsrecon:
274+
#### Using dnsrecon:
277275

278-
```
276+
```text
279277
dnsrecon -r $ip/$subnet -n $ip_to_check
280278
```
281279

@@ -355,7 +353,5 @@ dnsrecon -d zonetransfer.me -t axfr
355353
dnsenum zonetransfer.me
356354
```
357355

358-
359-
360356
If you like this content and would like to see more, please consider [buying me a coffee](https://www.buymeacoffee.com/zweilosec)!
361357

0 commit comments

Comments
 (0)