Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# show inodes by current dir
for i in `ls`; do echo -n "$i: "; find $i -printf "%i\n" | sort -u | wc -l; done
# better way
find -maxdepth 1 ! -name . -type d -print0 | xargs -0I{} bash -c "echo -n '{}: '; find '{}' | wc -l"
function count_inodes() {
find $1 -maxdepth 1 | wc -l
#!/bin/bash
ls -lahi | grep name
find -inum <INODE> -delete
@mdpuma
mdpuma / gist:b5a7fdc7f0a052f77732
Last active May 2, 2022 08:03
scan php infections
#!/bin/bash
find ! -perm 000 -type f -name \*.php -print0 | xargs -0 -n2 grep -E "mail\s*\(" |less
find ! -perm 000 -type f -name \*.php -print0 | xargs -0 -n2 grep -E 'eval\(|move_uploaded_file' |less
find ! -perm 000 -type f -name \*.php -print0 | xargs -0 -n2 grep 'eval(stripslashes' |less
find ! -perm 000 -type f -name \*.php -print0 | xargs -0 -n2 grep 'eval($_' |less
find ! -perm 000 -type f -name \*.php -print0 | xargs -0 -n2 grep 'base64_decode(' |less
find ! -perm 000 -type f -name \*.php -print0 | xargs -0 -n2 grep 'base64_encode(gzcompress' |less
find ! -perm 000 -type f -name \*.php -print0 | xargs -0 -n2 grep "\\\x" |less
find ! -perm 000 -type f -name \*.php -print0 | xargs -0 -n2 grep -E "(system|exec)\(" |less
#!/bin/sh
#
# Send 60-byte packets at maximum rate through eth1 to 10.0.0.2.
# Additional arguments are passed on to configure the device under pktgen;
# try "pkt_size BYTES" or "rate US" or "ratep PPS".
#
thread=$1
modprobe pktgen
@mdpuma
mdpuma / gist:4edfc877145b19d2aeb7
Last active April 18, 2016 15:45
strace process by user
#!/bin/bash
USER=nobody
strace $(pgrep -u $USER | xargs -I{} echo -n "-p {} ") 2>&1
@mdpuma
mdpuma / sleep_until.sh
Last active February 2, 2016 18:53 — forked from p0c/sleep_until.sh
shell function sleep until
#!/bin/bash
current_time=$(date +%s)
target_time=$(date -d "$*" +%s)
seconds=$(( $target_time - $current_time ))
echo "sleeping $seconds (`date -d "$*"`)"
sleep $seconds
# Usage:
@mdpuma
mdpuma / htaccess password location
Last active October 10, 2022 08:22
nginx + apache, http to https redirect
# cat httpd.conf
SetEnvIf X-Forwarded-Proto https HTTPS=on
# cat .htaccess
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
@mdpuma
mdpuma / post-mortem.md
Created February 20, 2016 19:53 — forked from joewiz/post-mortem.md
Recovery from nginx "Too many open files" error on Amazon AWS Linux

On Tue Oct 27, 2015, history.state.gov began buckling under load, intermittently issuing 500 errors. Nginx's error log was sprinkled with the following errors:

2015/10/27 21:48:36 [crit] 2475#0: accept4() failed (24: Too many open files) 2015/10/27 21:48:36 [alert] 2475#0: *7163915 socket() failed (24: Too many open files) while connecting to upstream...

An article at http://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/ provided directions that mostly worked. Below are the steps we followed. The steps that diverged from the article's directions are marked with an *.

    • Instead of using su to run ulimit on the nginx account, use ps aux | grep nginx to locate nginx's process IDs. Then query each process's file handle limits using cat /proc/pid/limits (where pid is the process id retrieved from ps). (Note: sudo may be necessary on your system for the cat command here, depending on your system.)
  1. Added fs.file-max = 70000 to /etc/sysctl.conf
  2. Added `nginx soft nofile 1
@mdpuma
mdpuma / androidv2 conn
Last active February 1, 2020 18:31
strongswan pki
conn %default
keyexchange=ikev2
type=tunnel
auto=add
# ike=aes256-sha1-modp1024!
# esp=aes256-sha1!
dpdaction=clear
dpddelay=300s
fragmentation=yes
left=%any
#!/bin/bash
# install pv, mysql, ssh
# dbs contain list of databases
cat dbs | while read i; do
echo "syncing '$i'"
ssh -n root@178.33.37.57 "mysqldump $i | gzip -c" | pv | gzip -d | mysql $i
done
# clone mysql users privileges