Skip to content

YARA · SEKOIA.IO Community

SEKOIA_Generic_Python_Reverse_Shell

Detects simple reverse shell written in Python

GenericSEKOIA.IO CommunityDetection Rule License 1.1Compiles with YARA-X
Author
Sekoia.io
Date
2023-12-08
Modified
2024-12-19
Score / Quality
75 / 80

What this rule detects

Detects simple reverse shell written in Python

It defines 4 patterns (4 text, 0 hex, 0 regex).

Summary generated from the rule's metadata and condition.

Rule source

generic-python-reverse-shell.yarDetection Rule License 1.1
rule SEKOIA_Generic_Python_Reverse_Shell : FILE
{
	meta:
		description = "Detects simple reverse shell written in Python"
		author = "Sekoia.io"
		id = "ab25f8db-e39d-4aa4-b431-cf5cd2e038e5"
		date = "2023-12-08"
		modified = "2024-12-19"
		reference = "https://github.com/SEKOIA-IO/Community"
		source_url = "https://github.com/SEKOIA-IO/Community/blob/a438a5901a211c2abdf75da9c93921ef187473d1/yara_rules/generic_python_reverse_shell.yar#L1-L18"
		license_url = "https://github.com/SEKOIA-IO/Community/blob/a438a5901a211c2abdf75da9c93921ef187473d1/LICENSE.md"
		logic_hash = "ced9923ef8018796545d93d9ac8ba3138dd7d4e79db742eb3babcd94c8d3c304"
		score = 75
		quality = 80
		tags = "FILE"
		version = "1.0"
		classification = "TLP:CLEAR"

	strings:
		$ = "import pty"
		$ = "lhost ="
		$ = "os.dup2(s.fileno(),0)"
		$ = "os.putenv(\"HISTFILE\",'/dev/null')"

	condition:
		filesize < 1KB and all of them
}

Strings (4 patterns)

IdentifierTypeValueModifiers
$text"import pty"
$text"lhost ="
$text"os.dup2(s.fileno(),0)"
$text"os.putenv(\"HISTFILE\",'/dev/null')"

Condition

filesize < 1KB and all of them

In plain words (Heuristic)

  • The file must be smaller than 1KB (a cheap guard that skips large files).
  • All patterns in the rule must match.

Test this rule in your browser

Drop a file to scan it with this rule using YARA-X compiled to WebAssembly. Nothing is uploaded.

Drop a file here or click to chooseScanned locally with YARA-X. Files up to 200 MB.

Open in editor

References

Licence & attribution

Author: Sekoia.io

Source repository: SEKOIA.IO Community @ a438a5901a

Licence: Detection Rule License 1.1 (repository licence)

Original rule

Mirrored via YARA Forge 20260927, which prefixes rule names with the source and adds normalised meta fields.

Rule id: ab25f8db-e39d-4aa4-b431-cf5cd2e038e5

Metadata

version1.0
classificationTLP:CLEAR

Tags:FILE