-
- Old code
exec_cmd('ping {ip}'.format(ip=ip))
- Rewritten code
exec_cmd(format_cmd('ping {ip}', ip=ip))
- Examples
format_cmd('ping {ip}', ip="$(rm -rf /)") $ ping '$(rm -rf /)' ping: cannot resolve $(rm -rf /): Unknown host
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
def get_key_from_dict_by_value(dictionary, value): | |
for k in dictionary: | |
if dictionary[k] == value: | |
return k |
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
#!/usr/bin/env python3 | |
import asyncio | |
from aiohttp import web | |
import argparse | |
import logging | |
from urllib import parse | |
logging.basicConfig(level=logging.DEBUG) | |
logger = logging.getLogger() |
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
import functools | |
def dec(func=None): | |
if func is None: | |
return lambda f: dec(f) | |
@functools.wraps(func) | |
def wrapper(*args, **kwargs): | |
print('wrapper') | |
return func(*args, **kwargs) |
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
Here is a quick tutorial to set up a basic PPTP VPN server on Ubuntu 12.04. | |
Install Necessary Packages | |
$ aptitude install ppp pptpd | |
Configure DNS Servers to Use When Clients Connect to this PPTP Server | |
$ nano /etc/ppp/pptpd-options | |
Modify OR Add the following lines in end | |
ms-dns 8.8.8.8 |
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
#!/usr/bin/env python2 | |
from email import header | |
from email.mime import audio | |
from email.mime import application | |
from email.mime import image | |
from email.mime import multipart | |
from email.mime import text | |
import logging | |
import mimetypes |
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
#/etc/rc.local | |
ipset create black_ips hash:ip | |
iptables -A INPUT -m set --match-set black_ips src -j DROP | |
grep "Failed password for" /var/log/auth.log | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort | uniq -c | awk '$1 > 5 { print $2}' | xargs -I{} ipset add black_ips {} | |
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
# to generate your dhparam.pem file, run in the terminal | |
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 |
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
#!/bin/bash | |
function get_ids { | |
echo `$@ --fields=id | tail -n+4 | head -n-1 | awk '{ print $2 }'` | |
} | |
function get_body { | |
echo `$@ | tail -n+4 | head -n-1` | |
} |
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
// https://www.joeshaw.org/dont-defer-close-on-writable-files/ | |
func helloNotes() error { | |
f, err := os.Create("/home/joeshaw/notes.txt") | |
if err != nil { | |
return err | |
} | |
defer f.Close() | |
if err = io.WriteString(f, "hello world"); err != nil { | |
return err |
OlderNewer