Test
Test
( Tech | Security | Linux | Bike | Misc ) ramblings
![]() |
llama.jpg |
#!/bin/bash
WINDOW=$1
MSG=$2
xdotool windowactivate $WINDOW;
while read -n1 i; do
case $i in
"") i="space" ;;
"\"") i="quotedbl" ;;
"@") i="at" ;;
"-") i="minus" ;;
";") i="semicolon" ;;
esac
xdotool key $i
sleep 0.01
done <<<"$MSG"
xdotool key Return
#include <sys/sendfile.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
//ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
int main(int argc, char **argv){
ssize_t sf_stat;
if (argc != 3){
printf("usage: %s in_file out_file\n", argv[0]);
return -1;
}
int in_fd = open(argv[1], O_RDONLY);
int out_fd = creat(argv[2], S_IRUSR|S_IWUSR);
if ((in_fd | out_fd) < 0){
perror("error opening file");
return -1;
}
do {
sf_stat = sendfile(out_fd, in_fd, NULL, 65536);
} while (sf_stat > 0);
if (sf_stat < 0){
perror("error copying file");
}
close(in_fd);
close(out_fd);
}
#!/usr/bin/python | |
import urllib2 | |
import sys | |
import argparse | |
import json | |
DEST_LANG="fr" | |
SOURCE_LANG="en" | |
def pull(phrase, source, dest): | |
phrase = urllib2.quote(phrase) | |
try: | |
opener = urllib2.build_opener() | |
opener.addheaders = [('User-agent', 'Mozilla/5.0')] | |
response = opener.open("http://translate.google.co.uk" + "/translate_a/t?client=webapp&sl=" + source + "&tl=" + dest + "&hl=en&sc=1&q=" + phrase) | |
except urllib2.HTTPError, err: | |
print "ERROR [" + err + "] Google says no" | |
sys.exit(-1) | |
except: | |
print "ERROR [UNKNOWN] Google really says no" | |
sys.exit(-2) | |
return json.loads(response.read()) | |
def parse(reply): | |
tran = "" | |
for s in reply['sentences']: | |
tran+=s['trans'] | |
return tran | |
def main(): | |
parser = argparse.ArgumentParser(description='A command line wrapper for Google Translate') | |
parser.add_argument('text', nargs='+', help='Profanities you would like to translate') | |
parser.add_argument('-s', default=SOURCE_LANG, metavar="source_lang", help="Language you know") | |
parser.add_argument('-d', default=DEST_LANG, metavar="dest_lang", help="Language you wish you knew") | |
parser.add_argument('--switch', '-w', action='store_true', help="Switch the default languages") | |
parser.add_argument('--log', '-l', metavar="log_file", help="Log to [file]") | |
args = parser.parse_args() | |
colour="\033[1;91m" # Red | |
colour_default="\033[0;39m" | |
original = ' '.join(args.text) | |
if (args.switch is False): | |
colour="\033[1;34m" # Blue | |
args.s, args.d = args.d, args.s | |
translation = parse(pull(original, args.d, args.s)) | |
if (args.log != None): | |
try: | |
fd = open(args.log, 'a') | |
except: | |
print "ERROR [FAILED TO OPEN FILE]" | |
sys.exit(-3); | |
fd.write(original + " -> " + translation + "\n") | |
print colour + translation + colour_default | |
if __name__ == '__main__': | |
main() |
[adam@localhost code]$ ./secret
Usage: ./secret password
[adam@localhost code]$ ./secret abc123
ERROR: Incorrect password
[adam@localhost code]$
[adam@localhost code]$ nm -D secret
w __gmon_start__
U __libc_start_main
U printf
U puts
U strlen
U strncmp
[adam@localhost code]$ cat load_me_first.c
#include <stdio.h>
#include <stdlib.h>
int strncmp(const char *cs, const char *ct, size_t count){
printf("[ Non-offical strncmp hit ]\n"
"\tcs = %s\n"
"\tct = %s\n",
cs, ct);
exit(0);
}
[adam@localhost code]$ gcc -shared -o load_me_first.so -fPIC load_me_first.c
[adam@localhost code]$ ls -la *.so
-rwxrwxr-x. 1 adam adam 8065 Nov 10 22:58 load_me_first.so
[adam@localhost code]$ LD_PRELOAD=./load_me_first.so ./secret "if only this was the password"
[ Non-offical strncmp hit ]
cs = qwerty
ct = if only this was the password
[adam@localhost code]$
[adam@localhost code]$ ./secret qwerty
)\ (__)
/ \ (oo)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cow trying out for a part
in the new JAWS movie
[adam@localhost code]$ time ./strcmp_bruter.py
made it.
Tell me and I forget, teach me and I may remember, involve me and I learn.
real 0m0.111s
user 0m0.043s
sys 0m0.050s
[adam@localhost code]$
[adam@localhost gnuplot]$ ping google.com -c 100 -ni 0.2 | awk -F [=\ ] {'print $(NF-1)'} | grep -E "[0-9]" > ping.dat
[adam@localhost gnuplot]$ head -n 5 ping.dat
27.3
22.2
23.2
72.7
26.4
[adam@localhost gnuplot]$ cat ping.gp
#!/usr/bin/gnuplot
set terminal png
set output "ping.png"
set ylabel "Delay (m/s)"
set xlabel "Number"
plot "ping.dat" with lines
[adam@localhost gnuplot]$ ./ping.gp
- set terminal png
- set output "ping.png"
+ set terminal dumb
[adam@localhost ~]$ pacmd list-sinks | grep index -A 1
index: 0
name: <alsa_output.pci-0000_00_03.0.hdmi-stereo-extra1>
--
* index: 1
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
[adam@localhost ~]$
[adam@localhost ~]$ pacmd set-default-sink 0
[adam@localhost ~]$ pacmd list-sink-inputs | grep -Ei "(available|sink|index|application\.name)" | sed s/^[[:space:]]*//g
>>> 1 sink input(s) available.
index: 39
sink: 1 <alsa_output.pci-0000_00_1b.0.analog-stereo>
application.name = "ALSA plug-in [plugin-container.#prelink#.QLz5gf (deleted)]"
[adam@localhost ~]$ pacmd move-sink-input 39 0 > /dev/null
[adam@localhost ~]$ pacmd list-sink-inputs | grep -Ei "(available|sink|index|application\.name)" | sed s/^[[:space:]]*//g
>>> 1 sink input(s) available.
index: 39
sink: 0 <alsa_output.pci-0000_00_03.0.hdmi-stereo-extra1>
application.name = "ALSA plug-in [plugin-container.#prelink#.QLz5gf (deleted)]"
[adam@localhost ~]$ pacmd load-module module-combine-sink sink_name="Combined" slaves=0,1 adjust_time=5
[adam@localhost ~]$ pacmd list-sinks | grep index -A 1
index: 0
name: <alsa_output.pci-0000_00_03.0.hdmi-stereo-extra1>
--
* index: 1
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
--
index: 2
name: <Combined>
[adam@localhost ~]$ pacmd set-default-sink 2
[adam@localhost ~]$ pacmd set-sink-volume 1 0x15000