Skip to content

Instantly share code, notes, and snippets.

View jrelo's full-sized avatar

hed0rah jrelo

View GitHub Profile
@jrelo
jrelo / 2-vars-bash.sh
Created October 5, 2019 20:55
2 simultaneous variables in bash loop
seq 3189 3193 > x.txt ; seq 5003 5008 > y.txt; while read -r x && read -r y <&3; do echo number wat${x}.hostgator.com wat${y}.hostgator.com ;done <x.txt 3<y.txt
@jrelo
jrelo / clr_conntrack.sh
Created September 14, 2019 17:22
clear conntracks for IP
/usr/sbin/conntrack -L |grep $1 | grep ESTAB |grep 'dport=$2' | awk '{ system("/usr/sbin/conntrack -D --orig-src '$1' --orig-dst " substr($6,5) " -p tcp --orig-port-src " substr($7,7) " --orig-port-dst $2");}';
@jrelo
jrelo / mrecent_string_block.sh
Created September 5, 2019 16:58
simple iptables -m recent string block
iptables -t mangle -N badz
iptables -t mangle -N blockz
iptables -t mangle -A PREROUTING -p tcp -m tcp --dport 80 -j blockz
iptables -t mangle -A badz -m recent --set --name terrible --rsource
iptables -t mangle -A blockz -p tcp -m tcp --dport 80 --tcp-flags FIN,SYN,RST,ACK SYN -m recent --update --seconds 3600 --name terrible --rsource -j DROP
iptables -t mangle -A blockz -p tcp -m tcp --dport 80 -m string --string "malicious_string" --algo bm --to 65535 -m recent --set --name bad --rsource
iptables -t mangle -A blockz -p tcp -m tcp --dport 80 -m string --string "malicious_string" --algo bm --to 65535 -m recent --update --seconds 10 --hitcount 3 --name bad --rsource -j badz
@jrelo
jrelo / ifdirectoryempty.sh
Created August 22, 2019 13:04
if directory is empty
#!/bin/bash
# Set the variable for bash behavior
shopt -s nullglob
shopt -s dotglob
# Die if dir name provided on command line
[[ $# -eq 0 ]] && { echo "Usage: $0 dir-name"; exit 1; }
# Check for empty files using arrays
chk_files=(${1}/*)
@jrelo
jrelo / addon_plus_pop.sh
Created June 18, 2019 18:18
addpop test emails + addon domain
# cpapi2 --user=tqqlzfna AddonDomain addaddondomain dir=/home/tqqlzfna/public_html/whatever.com newdomain=watever.com subdomain=wat
# /scripts/addpop test@watever.com apassword...
# mail -s "Test Subject" test@watever.com < /dev/null
@jrelo
jrelo / gist:3af2cd727c4118b3d9875deaf1978e13
Created May 9, 2019 20:16
vzprocess: ps with CTID filtration for OpenVZ
#!/usr/bin/perl
use strict;
use warnings;
unless (scalar @ARGV == 1) {
die "Parameter needed, please pass ctid as parameter";
}
my $ctid = $ARGV[0];
@jrelo
jrelo / bm.py
Created May 8, 2019 13:05
bind mounts pythong3
#!/usr/bin/python3
import os.path, re
from collections import namedtuple
MountInfo = namedtuple('MountInfo', ['mountid', 'parentid', 'devid', 'root', 'mountpoint', 'mountoptions', 'extra', 'fstype', 'source', 'fsoptions'])
mounts = {}
def unescape(string):
@jrelo
jrelo / learn_some_linux.txt
Created May 2, 2019 13:03
learn linux task list (from reddit)
This is what I tell people to do, who ask me "how do I learn to be a Linux sysadmin?".
1) Set up a KVM hypervisor.
2) Inside of that KVM hypervisor, install a Spacewalk server.
- Use CentOS 6 as the distro for all work below.
- For bonus points set up errata importation on the CentOS channels, so you can properly see security update advisory information.
3) Create a VM to provide named and dhcpd service to your entire environment.
- Set up the dhcp daemon to use the Spacewalk server as the pxeboot machine (thus allowing you to use Cobbler to do unattended OS installs).
- Make sure that every forward zone you create has a reverse zone associated with it.
- Use something like "internal.virtnet" (but not ".local") as your internal DNS zone.
@jrelo
jrelo / coproc.sh
Created April 24, 2019 12:34
coproc usage
coproc cat # Start cat in background
echo Hello >&${COPROC[1]} # Say "Hello" to cat
read LINE <&${COPROC[0]} # Read response
echo $LINE # cat replied "Hello"!
@jrelo
jrelo / zbx_pull.pl
Created February 26, 2019 18:29
zabbix pull
#!/usr/bin/env perl
use strict;
use warnings;
use Zabbix::Tiny;
$|++;
my %hostgroups = (
'Test' => "42",
);
my $zabbix = Zabbix::Tiny->new(
server => 'https://myzabbix.something.com/api_jsonrpc.php',