env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
tisdag 30 september 2014
torsdag 10 juli 2014
Floating point numbers ...
Floating point numbers have some unexpected properties.
Try this in your favourite language (if it has real floats)
Python:
Try this in your favourite language (if it has real floats)
Python:
>>> print 0.1 + 0.2 == 0.3
FalseC:
#include <stdio.h>
int main() { printf("%s\n", 0.1 + 0.2 == 0.3 ? "True" : "False");
}
$ gcc float.c -o float && ./float
False
fredag 4 juli 2014
Installing a specific branch of a python package with pip
pip install --user 'git+git://github.com/llvmpy/llvmpy@llvm-3.4'
onsdag 14 maj 2014
Parallela16 temperature
Reading the temperature for the Xilinx Zynq chip is done as described in http://forums.parallella.org/viewtopic.php?t=930
with
with
python -c "T=open('/sys/bus/iio/devices/iio:device0/in_temp0_raw').read(); T = (float(T) / 4096. * 503.975) - 273.15; print T"
tisdag 28 januari 2014
ARM debugging with Qemu and gdb
To set up a pty to capture the serial port info, use socat
which tells Qemu to start a gdb-server at port 1234 and wait (-S) until a gdb server attaches.
Make sure to have a gdb configured for arm targets, compiled with
socat -d -d pty ptywhich prints out which pty to connect Qemu's virtual serial port to, for instance /dev/pts/1, and the other pty, for instance /dev/pty/6, to which one may for instance attach a GNU Screen
screen /dev/pty/6Now run Qemu
QEMU_AUDIO_DRV=none qemu-system-arm \
-cpu cortex-a15 -machine vexpress-a15 \
-kernel /tmp/vmlinuz-3.10 -append "earlyprintk console=tty1 console=ttyAMA0" \
-nographic \
-gdb tcp:localhost:1234 -S -serial /dev/pts/1
which tells Qemu to start a gdb-server at port 1234 and wait (-S) until a gdb server attaches.
Make sure to have a gdb configured for arm targets, compiled with
./configure --target=arm-linux-gnueabiand run it. Connect to the qemu gdb-server with
make
target remote :1234To see the machine code, type
C-x ato enable the terminal interface that shows code cursor, and enable asm with
layout asm
måndag 29 april 2013
Enabling a bridge interface when you're on nfs root
When you enable a bridge interface with brctl from bridge-utils you loose network connectivity for a short while. This means trouble if you use nfs root or something that needs to have network to load the next command, or acces other files or directories.
Here's what to do. Warning! Understand what you do. If you are working logged in remotely and it screws up, you'll have to reboot the machine, because it has lost its access to the nfs root file system!
Anyway, here we go:
We must create a small rootfs on a directory that is not nfsrooted such as a tmpfs (a ram-based file system), there is often one mounted already. Look for one with mount.
I have a tmpfs mounted at /run. I notice that it is mounted as 'noexec' which means that I can't run commands from it. To solve that, remount it with the exec option set.
Then make a root dir called /run/root for instance.
Then copy over /lib and /bin (we don't need all of it, but we're lazy, remember!).
Put the stuff we need to do in a script file in the temp root, and then execute it from a chroot with busybox (or sh if you have put everything you need into the chroot). Make sure that you actually have busybox.
Here is what I have in my script (https://gist.github.com/anonymous/5480567):
Here's what to do. Warning! Understand what you do. If you are working logged in remotely and it screws up, you'll have to reboot the machine, because it has lost its access to the nfs root file system!
Anyway, here we go:
We must create a small rootfs on a directory that is not nfsrooted such as a tmpfs (a ram-based file system), there is often one mounted already. Look for one with mount.
I have a tmpfs mounted at /run. I notice that it is mounted as 'noexec' which means that I can't run commands from it. To solve that, remount it with the exec option set.
Then make a root dir called /run/root for instance.
Then copy over /lib and /bin (we don't need all of it, but we're lazy, remember!).
Put the stuff we need to do in a script file in the temp root, and then execute it from a chroot with busybox (or sh if you have put everything you need into the chroot). Make sure that you actually have busybox.
Here is what I have in my script (https://gist.github.com/anonymous/5480567):
fredag 15 mars 2013
Pure python sin
Pure python sin up to 6 decimals (nine degree Taylor expansion, no recursion, 11 mult, 1 div)
"""
f(x) = f(x)+f'(x)*x+f''(x)/2!*(x**2)+...
if f(x) = sin(x)
around 0 is
f(x) = sin(0)+cos(0)*x-sin(0)/2*x2-cos(0)/3!*x3+sin(0)/4!*x4+cos(0)/5!*x5+...
= x-x**3/6.+x**5/120.+...
"""
# constants
pi = 3.14159265358979
pi2 = pi / 2
k1 = 1. / (2 * 3)
k2 = 1. / (4 * 5)
k3 = 1. / (6 * 7)
k4 = 1. / (8 * 9)
def sin(x):
s = 1.0
if x < 0.0:
s = -s
x = -x
if x > pi2:
n = int(x / pi2)
x = x - pi2 * float(n)
if n & 1: x = pi2 - x
if n & 2: x = -x
x2 = x * x
return s*(x*(1.-k1*x2*(1.-k2*x2*(1.-k3*x2*(1.-k4*x2)))))
"""
f(x) = f(x)+f'(x)*x+f''(x)/2!*(x**2)+...
if f(x) = sin(x)
around 0 is
f(x) = sin(0)+cos(0)*x-sin(0)/2*x2-cos(0)/3!*x3+sin(0)/4!*x4+cos(0)/5!*x5+...
= x-x**3/6.+x**5/120.+...
"""
# constants
pi = 3.14159265358979
pi2 = pi / 2
k1 = 1. / (2 * 3)
k2 = 1. / (4 * 5)
k3 = 1. / (6 * 7)
k4 = 1. / (8 * 9)
def sin(x):
s = 1.0
if x < 0.0:
s = -s
x = -x
if x > pi2:
n = int(x / pi2)
x = x - pi2 * float(n)
if n & 1: x = pi2 - x
if n & 2: x = -x
x2 = x * x
return s*(x*(1.-k1*x2*(1.-k2*x2*(1.-k3*x2*(1.-k4*x2)))))
Prenumerera på:
Inlägg (Atom)