-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuseful_commands.html
801 lines (791 loc) · 29.3 KB
/
useful_commands.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
<!DOCTYPE html>
<html>
<head>
<title>Pentester Utils - Useful Commands</title>
<link rel="stylesheet" type="text/css" href="css/desert.css">
<link rel="stylesheet" type="text/css" href="css/custom_style.css">
<script type="text/javascript" src="js/run_prettify.js?autoload=false"></script>
</head>
<body onload="PR.prettyPrint()">
<ul class="nav">
<li><a href="index.html">Home</a></li>
<li><a href="useful_commands.html">Useful Commands</a></li>
<li><a href="python_scripts.html">Python Scripts</a></li>
</ul>
<hr>
<h1>Table of Content</h1>
<ol>
<li><a href="#routes">Routes</a>
<ul>
<li><a href="#routes-show">Show</a></li>
<li><a href="#routes-add">Add</a></li>
</ul>
</li>
</ol>
<h1 id="routes">Routes</h1>
<h2 id="routes-show">Show</h2>
<p>
<pre class="prettyprint">
<code>
$ route
</code>
</pre>
</p>
<h2 id="routes-add">Add</h2>
<p>
<pre class="prettyprint">
<code>
$ ip route add <net_address_in_cdr> via <interface_gateway>
</code>
</pre>
</p>
<h1 id="linux-commands">Linux Commands</h1>
<table>
<thead>
<tr>
<th>
COMMAND
</th>
<th>
DESCRIPTION
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="prettyprint inline">netstat -tulpn</code>
</td>
<td>
Show Linux network ports with process ID’s (PIDs)
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">watch ss -stplu</code>
</td>
<td>
Watch TCP, UDP open ports in real time with socket summary.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">lsof -i</code>
</td>
<td>
Show established connections.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">macchanger -m MACADDR INTR</code>
</td>
<td>
Change MAC address on KALI Linux.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">ifconfig eth0 192.168.2.1/24</code>
</td>
<td>
Set IP address in Linux.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">ifconfig eth0:1 192.168.2.3/24</code>
</td>
<td>
Add IP address to existing network interface in Linux.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">ifconfig eth0 hw ether MACADDR</code>
</td>
<td>
Change MAC address in Linux using ifconfig.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">ifconfig eth0 mtu 1500</code>
</td>
<td>
Change MTU size Linux using ifconfig, change 1500 to your desired MTU.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">dig -x 192.168.1.1 </code>
</td>
<td>
Dig reverse lookup on an IP address.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">host 192.168.1.1 </code>
</td>
<td>
Reverse lookup on an IP address, in case dig is not installed.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">dig @192.168.2.2 domain.com -t AXFR</code>
</td>
<td>
Perform a DNS zone transfer using dig.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">host -l domain.com nameserver</code>
</td>
<td>
Perform a DNS zone transfer using host.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">nbtstat -A x.x.x.x</code>
</td>
<td>
Get hostname for IP address.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">ip addr add 192.168.2.22/24 dev eth0</code>
</td>
<td>
Adds a hidden IP address to Linux, does not show up when performing an ifconfig.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">tcpkill -9 host google.com</code>
</td>
<td>
Blocks access to google.com from the host machine.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">echo "1" > /proc/sys/net/ipv4/ip_forward</code>
</td>
<td>
Enables IP forwarding, turns Linux box into a router – handy for routing traffic through a box.
</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">echo "8.8.8.8" > /etc/resolv.conf</code>
</td>
<td>
Use Google DNS.
</td>
</tr>
</tbody>
</table>
<h2 id="lc-sys">System Information Commands</h2>
<p>
Useful for local enumeration
</p>
<table>
<thead>
<tr>
<th>COMMAND</th>
<th>DESCRIPTION</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="prettyprint inline">whoami</code>
</td>
<td>Shows currently logged in user on Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">id</code>
</td>
<td>Shows currently logged in user and groups for the user.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">last</code>
</td>
<td>Shows last logged in users.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">mount</code>
</td>
<td>Show mounted drives.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">df -h</code>
</td>
<td>Shows disk usage in human readable output.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">echo "user:passwd" | chpasswd</code>
</td>
<td>Reset password in one line.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">getent passwd</code>
</td>
<td>List users on Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">strings /usr/local/bin/blah</code>
</td>
<td>Shows contents of none text files, e.g. whats in a binary.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">uname -ar</code>
</td>
<td>Shows running kernel version.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">PATH=$PATH:/my/new-path</code>
</td>
<td>Add a new PATH, handy for local FS manipulation.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">history</code>
</td>
<td>Show bash history, commands the user has entered previously.</td>
</tr>
</tbody>
</table>
<h2 id="lc-user">Linux User Management</h2>
<table>
<thead>
<tr>
<th>COMMAND</th>
<th>DESCRIPTION</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="prettyprint inline">whoami</code>
</td>
<td>Shows currently logged in user on Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">id</code>
</td>
<td>Shows currently logged in user and groups for the user.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">last</code>
</td>
<td>Shows last logged in users.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">mount</code>
</td>
<td>Show mounted drives.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">df -h</code>
</td>
<td>Shows disk usage in human readable output.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">echo "user:passwd" | chpasswd</code>
</td>
<td>Reset password in one line.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">getent passwd</code>
</td>
<td>List users on Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">strings /usr/local/bin/blah</code>
</td>
<td>Shows contents of none text files, e.g. whats in a binary.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">uname -ar</code>
</td>
<td>Shows running kernel version.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">PATH=$PATH:/my/new-path</code>
</td>
<td>Add a new PATH, handy for local FS manipulation.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">history</code>
</td>
<td>Show bash history, commands the user has entered previously.</td>
</tr>
</tbody>
</table>
<h2 id="lc-file">Linux File Commands</h2>
<table>
<thead>
<tr>
<th>COMMAND</th>
<th>DESCRIPTION</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="prettyprint inline">df -h blah</code>
</td>
<td>Display size of file / dir Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">diff file1 file2</code>
</td>
<td>Compare / Show differences between two files on Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">md5sum file</code>
</td>
<td>Generate MD5SUM Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">md5sum -c blah.iso.md5</code>
</td>
<td>Check file against MD5SUM on Linux, assuming both file and .md5 are in the same dir.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">file blah</code>
</td>
<td>Find out the type of file on Linux, also displays if file is 32 or 64 bit.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">dos2unix</code>
</td>
<td>Convert Windows line endings to Unix / Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">base64 < input-file > output-file</code>
</td>
<td>Base64 encodes input file and outputs a Base64 encoded file called output-file.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">base64 -d < input-file > output-file</code>
</td>
<td>Base64 decodes input file and outputs a Base64 decoded file called output-file.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">touch -r ref-file new-file</code>
</td>
<td>Creates a new file using the timestamp data from the reference file, drop the -r to simply create a file.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">rm -rf</code>
</td>
<td>Remove files and directories without prompting for confirmation.</td>
</tr>
</tbody>
</table>
<h2 id="lc-samba">Samba Commands</h2>
<p>
Connect to a Samba share from Linux.
<pre class="prettyprint">
<code>
$ smbmount //server/share /mnt/win -o user=username,password=password1
$ smbclient -U user \\\\server\\share
$ mount -t cifs -o username=user,password=password //x.x.x.x/share /mnt/share
</code>
</pre>
</p>
</table>
<h2 id="lc-shell">Breaking Out of Limited Shells</h2>
<p>
The Python trick:
<pre class="prettyprint">
<code>
$ python -c 'import pty;pty.spawn("/bin/bash")'
$ echo os.system('/bin/bash')
$ /bin/sh -i
</code>
</pre>
</p>
<h2 id="lc-misc">Misc Commands</h2>
<table>
<thead>
<tr>
<th>COMMAND</th>
<th>DESCRIPTION</th>
</tr>
</thead><tbody>
<tr>
<td>
<code class="prettyprint inline">init 6</code>
</td>
<td>Reboot Linux from the command line.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">gcc -o output.c input.c</code>
</td>
<td>Compile C code.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">gcc -m32 -o output.c input.c</code>
</td>
<td>Cross compile C code, compile 32 bit binary on 64 bit Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">unset HISTORYFILE</code>
</td>
<td>Disable bash history logging.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">rdesktop X.X.X.X</code>
</td>
<td>Connect to RDP server from Linux.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">kill -9 $$</code>
</td>
<td>Kill current session.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">chown user:group blah</code>
</td>
<td>Change owner of file or dir.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">chown -R user:group blah</code>
</td>
<td>Change owner of file or dir and all underlying files / dirs – recersive chown.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">chmod 600 file</code>
</td>
<td>Change file / dir permissions, see [Linux File System Permissons](#linux-file-system-permissions) for details.</td>
</tr>
</tbody>
</table>
<p>
Clear bash history:
<pre class="prettyprint">
<code>
$ ssh user@X.X.X.X | cat /dev/null > ~/.bash_history
</code>
</pre>
</p>
<h2 id="lc-perms">Linux File System Permissions</h2>
<table>
<thead>
<tr>
<th>VALUE</th>
<th>MEANING</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="prettyprint inline">777</code>
</td>
<td>
<code class="prettyprint inline">rwxrwxrwx</code> No restriction, global WRX any user can do anything.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">755</code>
</td>
<td>
<code class="prettyprint inline">rwxr-xr-x</code> Owner has full access, others can read and execute the file.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">700</code>
</td>
<td>
<code class="prettyprint inline">rwx------</code> Owner has full access, no one else has access.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">666</code>
</td>
<td>
<code class="prettyprint inline">rw-rw-rw-</code> All users can read and write but not execute.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">644</code>
</td>
<td>
<code class="prettyprint inline">rw-r--r--</code> Owner can read and write, everyone else can read.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">600</code>
</td>
<td>
<code class="prettyprint inline">rw-------</code> Owner can read and write, everyone else has no access.</td>
</tr>
</tbody>
</table>
</p>
<h2 id="lc-dirs">Linux Directories</h2>
<table>
<thead>
<tr>
<th>DIRECTORY</th>
<th>DESCRIPTION</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="prettyprint inline">/</code>
</td>
<td>/ also know as “slash” or the root.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/bin</code>
</td>
<td>Common programs, shared by the system, the system administrator and the users.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/boot</code>
</td>
<td>Boot files, boot loader (grub), kernels, vmlinuz</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/dev</code>
</td>
<td>Contains references to system devices, files with special properties.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/etc</code>
</td>
<td>Important system config files.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/home</code>
</td>
<td>Home directories for system users.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/lib</code>
</td>
<td>Library files, includes files for all kinds of programs needed by the system and the users.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/lost+found</code>
</td>
<td>Files that were saved during failures are here.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/mnt</code>
</td>
<td>Standard mount point for external file systems.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/media</code>
</td>
<td>Mount point for external file systems (on some distros).</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/net</code>
</td>
<td>Standard mount point for entire remote file systems – nfs.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/opt</code>
</td>
<td>Typically contains extra and third party software.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/proc</code>
</td>
<td>A virtual file system containing information about system resources.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/root</code>
</td>
<td>root users home dir.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/sbin</code>
</td>
<td>Programs for use by the system and the system administrator.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/tmp</code>
</td>
<td>Temporary space for use by the system, cleaned upon reboot.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/usr</code>
</td>
<td>Programs, libraries, documentation etc. for all user-related programs.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/var</code>
</td>
<td>Storage for all variable files and temporary files created by users, such as log files, mail queue, print spooler.
Web servers, Databases etc.</td>
</tr>
</tbody>
</table>
</p>
<h2 id="lc-cool-dirs">Linux Interesting Files / Directories</h2>
<table>
<thead>
<tr>
<th>DIRECTORY</th>
<th>DESCRIPTION</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="prettyprint inline">/etc/passwd</code>
</td>
<td>Contains local Linux users.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/etc/shadow</code>
</td>
<td>Contains local account password hashes.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/etc/group</code>
</td>
<td>Contains local account groups.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/etc/init.d/</code>
</td>
<td>Contains service init script – worth a look to see whats installed.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/etc/hostname</code>
</td>
<td>System hostname.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/etc/network/interfaces</code>
</td>
<td>Network interfaces.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/etc/resolv.conf</code>
</td>
<td>System DNS servers.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/etc/profile</code>
</td>
<td>System environment variables.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">~/.ssh/</code>
</td>
<td>SSH keys.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">~/.bash_history</code>
</td>
<td>Users bash history log.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/var/log/</code>
</td>
<td>Linux system log files are typically stored here.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/var/adm/</code>
</td>
<td>UNIX system log files are typically stored here.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/var/log/apache2/access.log</code>
<p></p>
<p>
<code class="prettyprint inline">/var/log/httpd/access.log</code>
</p>
</td>
<td>Apache access log file typical path.</td>
</tr>
<tr>
<td>
<code class="prettyprint inline">/etc/fstab</code>
</td>
<td>File system mounts.</td>
</tr>
</tbody>
</table>
</body>
</html>