You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: linux-1/linux-basics.md
+108-85
Original file line number
Diff line number
Diff line change
@@ -109,30 +109,30 @@ TODO: Add screenshots/code examples for each command; put commands in tables; cl
109
109
110
110
### Special Symbols
111
111
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\)||
136
136
137
137
### Recover an unresponsive terminal
138
138
@@ -277,9 +277,9 @@ Everything in Linux is a file, even directories and devices. Directories have so
277
277
|`touch $fileName`| Create a new blank file with this name |
278
278
|`cp $file [/path/to/]$newFile`| Copy file from one location to another. If no location is specified, creates the copy in the same directory. |
279
279
|`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. |
281
281
|`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`. |
283
283
|`mkdir [/path/to/]$dir`| Makes a new empty directory |
284
284
|`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. |
285
285
|`rmdir $dir`| Deletes an empty directory |
@@ -293,7 +293,7 @@ Everything in Linux is a file, even directories and devices. Directories have so
293
293
|`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 |
294
294
|`awk`| A programming language for text processing. Can do many many things. |
295
295
|`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. |
297
297
|`sort`||
298
298
|`uniq`||
299
299
@@ -305,118 +305,141 @@ cat > $fileName
305
305
306
306
### File Permissions
307
307
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
309
315
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:
311
317
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.
313
322
314
-
r = read\
315
-
w = write\
316
-
x = execute
323
+
The permissions `-rwxrwxrwx` mean that the anyone can read, write and execute the file.
317
324
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.
319
326
320
-
`-rwxrwxrwx`
327
+
#### The chmod command
321
328
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:
328
330
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
+
```
330
334
331
335
#### Octal notation
332
336
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.
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\).
353
357
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:
357
359
358
-
`chmod 777 file`
360
+
```bash
361
+
chmod 777 $file
362
+
```
359
363
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.
361
365
362
-
u = user\
363
-
g = group\
364
-
o = others\
365
-
a = u+g+o (all)
366
+
#### ugoa+rwx notation
366
367
367
-
You can also give permissions using this method :
368
+
In this notation format, there are three main components:
368
369
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.
370
373
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.
372
375
373
-
`chmod a-x file`
376
+
Examples:
374
377
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
+
```
376
383
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\)
378
399
379
400
Other than just read and write, you can also set some other permissions like SUID and GUID.
380
401
381
402
`chmod 4000 file`
382
403
383
404
`chmod +s file`
384
405
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.
386
407
387
408
`chmod 2000 file`
388
409
389
410
`chmod +g file`
390
411
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)<- pull more information from here and add
392
417
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.
396
419
397
420
`chmod 1000 folder`
398
421
399
422
`chmod +t folder`
400
423
401
424
Both the above examples set the sticky bit to the folders
402
425
403
-
Examples:
404
-
`chmod 1744 file`
426
+
Examples: `chmod 1744 file`
405
427
406
428
This would set the sticky bit, give all permissions to the owner and only read permission to the group and others
407
429
408
430
`chmod 0600 file`
409
431
410
432
This would only give the owner read and write permission, but not execute permission.
411
433
412
-
#### chown command
434
+
#### The chown command
413
435
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.
415
437
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
+
```
419
441
442
+
The above command would change the owner of the file to `$user` and also the group to `$group`.
420
443
421
444
### File compression and encryption
422
445
@@ -506,7 +529,7 @@ TODO: add more information on mounting and using network shares \(issue [\#10](h
506
529
|`apt show $package`| Show details about the specified package |
507
530
|`sudo apt install $package`| Installs the specified package \(and any dependencies\). |
508
531
|`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\). |
510
533
|`alien $file.rpm`| Convert rpm to Debian packages |
Copy file name to clipboardExpand all lines: web/dns.md
+5-9
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
{% hint style="success" %}
4
4
Hack Responsibly.
5
5
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.
7
7
{% endhint %}
8
8
9
9
## Hosts File
@@ -36,7 +36,7 @@ DNS offers a variety of information about public \(and sometimes private!\) orga
0 commit comments