$in = fopen("php://stdin","r");
while ($l =$fgets($in, 1024)) {
$a = preg_split('/\s+/', $l);
while(list($k, $v) = each($a)) {
...
foreach($c as $k=> $v) ...
all about go, ruby, python, perl, java, scala, osgi, RCP computing, network, hacking, security, encryption. and other interesting stuff
Sonntag, 5. Juli 2009
PHP: some stuff
CMDs: some shell commandos, linux
lpr -Plp Datei # datei ausdrucken
fuser -k /dev/lp0 # alle dienste die den /dev/lp0 benutzen toeten
#/dev/usb/lp0
scsi-scanner /dev/sg0
set -o nochlobber
git-rev-tree --bisect ^good1 ^good2 bad > git/refs/headers/tryN
git checkout tryN
^goodx > v2.6.12 bad > master
movw%bx, (%rsi) <-> recvfrom()
/usr/sbin/snort -b -m 027 -D -N -c /etc/snort/snort.conf -d -u snort -g snort -i eth1
iptables -A INPUT -ptcp -s PVT_IP_HERE -d 0/0
wget -p nur inhalt,
wget -r -np nur unterverzeichniss, nicht von root an
test -x $1 || exit 5
find /proc -type s
ls -Rr /proc/[0-9]* | fgrep ^s
fuser -k /dev/lp0 # alle dienste die den /dev/lp0 benutzen toeten
#/dev/usb/lp0
scsi-scanner /dev/sg0
set -o nochlobber
git-rev-tree --bisect ^good1 ^good2 bad > git/refs/headers/tryN
git checkout tryN
^goodx > v2.6.12 bad > master
movw%bx, (%rsi) <-> recvfrom()
/usr/sbin/snort -b -m 027 -D -N -c /etc/snort/snort.conf -d -u snort -g snort -i eth1
iptables -A INPUT -ptcp -s PVT_IP_HERE -d 0/0
wget -p nur inhalt,
wget -r -np nur unterverzeichniss, nicht von root an
test -x $1 || exit 5
find /proc -type s
ls -Rr /proc/[0-9]* | fgrep ^s
Freitag, 3. Juli 2009
PYTHON: get your own exception catcher
you can set your own exception handler, this is done by
for that you must define a function, with following parameters:
then you can call an exception
5/0
=>
whoaaa my exception
=>
['Traceback (most recent call last):\n', ' File "./t1.py", line 37, in\n 5/0\n', 'ZeroDivisionError: integer division or modulo by zero\n']
traceback.format_exception(...) return us a list of information
as a normal exception traceback
info about sys.xxx
sys.excepthook = your_func
for that you must define a function, with following parameters:
def your_func(exc_type, exc_obj, exc_tb):
print "whoaaa my exception"
then you can call an exception
5/0
=>
whoaaa my exception
def your_func(exc_type, exc_obj, exc_tb):
import traceback
l = traceback.format_exception(exc_type, exc_obj, exc_tb)
print type(l)
print l
=>
['Traceback (most recent call last):\n', ' File "./t1.py", line 37, in
traceback.format_exception(...) return us a list of information
as a normal exception traceback
info about sys.xxx
Donnerstag, 2. Juli 2009
OSGi: ogsi or wtf?
small info about OSGi
first we have OGSI and OSGi:
1) OGSI: Open Grid Services Infrastructure
2) OSGi: a framework for component based programming
here I talk about OSGi
Wiki
Why OSGI
OGSi Equinox: http://www.eclipse.org/equinox/
OSGi page
specifications v4
simple tutorial
first we have OGSI and OSGi:
1) OGSI: Open Grid Services Infrastructure
2) OSGi: a framework for component based programming
here I talk about OSGi
Wiki
Why OSGI
OGSi Equinox: http://www.eclipse.org/equinox/
OSGi page
specifications v4
simple tutorial
PYTHON: simple scanner in python
this is a simple scanner in python.
work: call a system ping (with popen() ) and look for ttl count.
if count ~64 -> linux, count ~128 -> windows, count ~255 -> BSD/Router
then it connect to well known ports and look for respond.
limits: only certain ports and only TCP
trace2.py
###################################################################
###################################################################
work: call a system ping (with popen() ) and look for ttl count.
if count ~64 -> linux, count ~128 -> windows, count ~255 -> BSD/Router
then it connect to well known ports and look for respond.
limits: only certain ports and only TCP
trace2.py
###################################################################
#!/usr/bin/python
import sys, os, socket, re
class Scan:
def __init__(self):
#print "create socket ..."
self.scanNew=None
self.allPorts={"ftp-data":20, "ftp":21,"smtp":25, "http":80, "pop3":110, "imap3":220, "https":443,
"ldap":389 }
self.linuxPorts={"ssh":22, "dns":53, "snmp":161, "snmp-trap":162}
self.windowPorts={"netbios-ns":137, "netbios-dgm":138, "netbios-ssn":139,"microsoft-ds":445 }
def ping(self, ip):
findttl = re.compile(r"ttl=(\d{1,3}) ")
pingpipe = os.popen("ping -W 1 -c 1 "+ip,"r")
for line in pingpipe.readlines():
if "ttl" in line:
result = re.findall(findttl,line)
return int(result[0])
return -1
def connectTCP(self, ip, port, portname):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
s.connect((ip, port))
print "connect to %s : %d (%s) was succesfull"%(ip, port, portname)
except:
pass
#print "failing to connect %s : %d (%s)"%(ip, port, portname)
s.close()
def scann(self, ip):
ttl=self.ping(ip)
if( ttl==-1):
print "IP %s not reachable"%ip
elif( ttl==0 ):
print "huch, ttl is zero"
elif( ttl>0 and ttl<65 ):
print " %s possible LINUX and is Alive"%ip
for port in self.allPorts.keys():
self.connectTCP(ip, self.allPorts[port], port)
for port in self.linuxPorts.keys():
self.connectTCP(ip, self.linuxPorts[port], port)
elif( ttl>64 and ttl<129 ):
print " %s possible WINDOWS and is Alive"%ip
for port in self.allPorts.keys():
self.connectTCP(ip, self.allPorts[port], port)
for port in self.windowPorts.keys():
self.connectTCP(ip, self.windowPorts[port], port)
else:
print " %s possible BSD or Router and is Alive"%ip
for port in self.allPorts.keys():
self.connectTCP(ip, self.allPorts[port], port)
for port in self.linuxPorts.keys():
self.connectTCP(ip, self.linuxPorts[port], port)
if( len(sys.argv) != 4):
print "%s ip(first triple) begin end"%sys.argv[0]
print " example:"
print " %s 123.45.67 10 20"%sys.argv[0]
sys.exit(2)
iptriple=sys.argv[1]
begin=int(sys.argv[2])
end=int(sys.argv[3])
scan=Scan()
for ip4 in range(begin, end):
ip="%s.%d"%(iptriple,ip4)
scan.scann(ip)
###################################################################
Mittwoch, 1. Juli 2009
C, REGEX
learn regular expression in C
info:
http://www.opengroup.org/onlinepubs/007908799/xsh/regex.h.html
structuren:
example: regex1.c
#################################################
#################################################
"\\b[A-Za-z0-9._%+-]+@(gmail|googlemail)+\\.[a-zA-Z]{2,4}\\b": example pattern
regcomp(): compile the seek string (pattern)
regexec(): seek for a pattern in string
struct regmatch_t
further functions:
regerror(): error handling
regfree (): free buffers
info:
http://www.opengroup.org/onlinepubs/007908799/xsh/regex.h.html
#include <regex.h>
structuren:
regex_t preg;
regmatch_t pmatch[100];
example: regex1.c
#################################################
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <regex.h>
int main() {
int err;
char err_str[200];
char results[500];
int i,j,k=0;
regex_t preg;
regmatch_t pmatch[100];
char *buf="blub blub blub@googlemail.com adslfku asdf@gmail.com oasduf";
if( (err = regcomp(&preg, "\\b[A-Za-z0-9._%+-]+@(gmail|googlemail)+\\.[a-zA-Z]{2,4}\\b", REG_EXTENDED)) != 0) {
printf("regcomp error\n");
return -1;
}
if( (err = regexec(&preg, buf, preg.re_nsub, pmatch, 0)) != 0) {
regerror(err, &preg, err_str, 200);
printf("%s\n",err_str);
return -1;
} else {
for(i = 0; i < preg.re_nsub; i++) {
if(pmatch[i].rm_so == -1) continue;
for(j = pmatch[i].rm_so; j < pmatch[i].rm_eo; j++)
results[k++] = buf[j];
results[k] = '|';
results[++k] = '\0';
}
}
printf(">> results: %s\n", results);
regfree(&preg);
return 0;
}
#################################################
"\\b[A-Za-z0-9._%+-]+@(gmail|googlemail)+\\.[a-zA-Z]{2,4}\\b": example pattern
regcomp(): compile the seek string (pattern)
regexec(): seek for a pattern in string
struct regmatch_t
typedef struct
{
regoff_t rm_so; /* Byte offset from string's start to substring's start. */
regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
} regmatch_t;
further functions:
regerror(): error handling
regfree (): free buffers
C, CURL: simple tutorial: libcurl with C
coding libcurl in C
homepage: http://curl.haxx.se/
download: http://curl.haxx.se/download.html
latest version: latest:curl-7.19.5
libcurl: http://curl.haxx.se/libcurl/
all about libcurl with C: http://curl.haxx.se/libcurl/c/
You must include:
compile
gcc libcurl1.c -o libcurl1 -lcurl
important structures:
CURL *curl;
CURLcode curl_res;
CURLINFO info;
Start a libcurl easy session
curl = curl_easy_init();
see more info: http://curl.haxx.se/libcurl/c/curl_easy_init.html
set options for a curl easy handle
curl_easy_setopt(CURL *handle, CURLoption option, parameter);
CURLOPT_WRITEDATA Data pointer to pass to the file write function
curl_easy_setopt(curl, CURLOPT_WRITEDATA, tmp);
tmp: FILE handle
set proxy
curl_easy_setopt(curl, CURLOPT_PROXY, pxy);
Perform a file transfer
curl_easy_perform(CURL * handle );
End a libcurl easy session
curl_easy_cleanup(curl);
set an url
curl_easy_setopt(curl, CURLOPT_URL, url);
set file handle, where the data get writed
curl_easy_setopt(curl, CURLOPT_WRITEDATA, tmp);
download the page
curl_res = curl_easy_perform(curl);
get http status code
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
get size of downloaded page
curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &c_length);
sample: libcurl1.c
##########################################
##########################################
./libcurl1
init curl session
set url to download
set file handler to write
download the file
file downloaded
get http return code
http code: 200
get size of download page
length: 6969
END: close all files and sessions
homepage: http://curl.haxx.se/
download: http://curl.haxx.se/download.html
latest version: latest:curl-7.19.5
libcurl: http://curl.haxx.se/libcurl/
all about libcurl with C: http://curl.haxx.se/libcurl/c/
You must include:
<curl/curl.h>
compile
gcc libcurl1.c -o libcurl1 -lcurl
important structures:
CURL *curl;
CURLcode curl_res;
CURLINFO info;
Start a libcurl easy session
curl = curl_easy_init();
see more info: http://curl.haxx.se/libcurl/c/curl_easy_init.html
set options for a curl easy handle
curl_easy_setopt(CURL *handle, CURLoption option, parameter);
CURLOPT_WRITEDATA Data pointer to pass to the file write function
curl_easy_setopt(curl, CURLOPT_WRITEDATA, tmp);
tmp: FILE handle
set proxy
curl_easy_setopt(curl, CURLOPT_PROXY, pxy);
Perform a file transfer
curl_easy_perform(CURL * handle );
End a libcurl easy session
curl_easy_cleanup(curl);
set an url
curl_easy_setopt(curl, CURLOPT_URL, url);
set file handle, where the data get writed
curl_easy_setopt(curl, CURLOPT_WRITEDATA, tmp);
download the page
curl_res = curl_easy_perform(curl);
get http status code
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
get size of downloaded page
curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &c_length);
sample: libcurl1.c
##########################################
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode curl_res;
CURLINFO info;
long http_code;
double c_length;
FILE *tmp;
tmp=fopen("/tmp/google_index.html", "w");
if(tmp==NULL) {
printf("ERROR to open file /tmp/google_index.html\n");
exit(2);
}
printf("init curl session\n");
curl = curl_easy_init();
printf("set url to download\n");
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.de/index.html");
printf("set file handler to write\n");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, tmp);
printf("download the file\n");
curl_res = curl_easy_perform(curl);
if(curl_res==0) {
printf("file downloaded\n");
} else {
printf("ERROR in dowloading file\n");
fclose(tmp);
curl_easy_cleanup(curl);
}
printf("get http return code\n");
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
printf("http code: %lu\n", http_code);
printf("get size of download page\n");
curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &c_length);
printf("length: %g\n", c_length);
printf("END: close all files and sessions\n");
fclose(tmp);
curl_easy_cleanup(curl);
return 0;
}
##########################################
./libcurl1
init curl session
set url to download
set file handler to write
download the file
file downloaded
get http return code
http code: 200
get size of download page
length: 6969
END: close all files and sessions
Abonnieren
Posts (Atom)