VNC Robot
October 8th, 2009
Today at work I had a interesting request. Make a screenshot of a Flash application and send this the customer by mail every 5 minutes or so. First I though that it would be best to utilize some Actionscript with PHP/GD. This was ok but the other guys seemed to prefer some other hack. So I came up with using something like Browsershots, or some CutyCapt/IECapt, Python, Django combination. This seemed too complicated though.
So I finally settled with using VNC Robot. This thing is actually really funny, its like (shudder) Windows Scripting Host in VNC. Perfect!.
Originally I also looked into Ruby/Mechanize and other alike but with Flash thats a problem these days...
Here is a sample script I created and other nifty examples can be found here.
# Open Firefox from start menu
Mouse move to=x:145,y:755 wait=1000
Mouse click count=1
# Go to location bar
Mouse move to=x:262,y:65 wait=1000
Mouse click count=1
# Go to webpage
# Press Ctrl+l wait=1000
Press Backspace count=20
Type "http://10.0.0.9" wait=1000
Press Enter wait=6000
# Go to login form
Press Tab wait=1000
Type "usernamewashere" wait=1000
Press Tab wait=1000
Type "passwordwashere" wait=1000
# Skip over the "Do you want to remember password question"
Press Enter wait=1000
Press Enter wait=1000
Wait 10000
# Take a screenshot and send it to John
Screenshot /tmp/stock.jpg
Sendmail subject="XYZ Application stock on {_DATE}" from="root@yourmachine" to="foobar@blahblubb.org"
server="localhost" attach="/tmp/stock.jpg"
# Close the browser so that we can rerun the script safely
Press Alt+F4 wait=500
Press Alt+F4 wait=500
The result looks like this (scaled down).
RSS Reader Extreme: NewsBeuter a Mutt-like Feedreader
February 17th, 2009
You read RSS Feeds right? Well, if you don't know what RSS or ATOM Feeds are then maybe you should check out the Wikipedia pages first.
I don't know what kind of feedreaders you use, but I liked for some time liferea. That was rather a hate/love relationship because I was never really fond of the need of using my mouse to read something. This is were NewsBeuter comes into play.
Its a feedreader which follows the Mutt-like philosophy and allows you to quickly skim through your feeds hitting only ``n'' on your keyboard everything on a curses based CLI. This thing is pretty feature complete (version 1.3+) and it is good enough for painless reading experience, heck you can even use tagging and advanced search functions.
(Screencast of v0.2)
Debian GNU/Linux currently has the 1.3-1 binary into their package repo so there is no need to build that thing for yourself. (its easy though).
Oh, did I forget you can pipe the feeds into your own scripts to change the content/markup to your own needs? Nice, no more website loading :)
Seriously, if you wanted to increase your productivity - go check it out.
Autojump, or a "cd" that remembers.
January 22nd, 2009
You are going to love this thing, believe me. You work on the CLI and jump always around from directory to directory? Well, you tried "Ctrl+r" I suppose. Frankly, it sucks. Sure you can cycle through the items but its just to stupid. We all want to save keystrokes so try this instead:
Sh/Bash Shell Users: Autojump j.sh implementation.
Zsh Shell Users: Autojump j.sh zsh port.
Original idea came from here: AutoJump.
So how does it work? Well download the script according to your shell and source it. Meaning either put it directly into your .zshrc or .bashrc or source the file. Then just work normally for some time, cd around like you normally work. Now you can do a j regex instead of cycling through the history with ctrl+r. The script will guess what you want ! Neat..
UPDATE: See the comments for a interesting suggestion from Martin, about WCD (http://www.xs4all.nl/~waterlan/).
Aptitude not your super cow ;)
December 2nd, 2008
Sorry for the long break everybody. Hope somebody still has me in his/her rss reader...
Sometimes when apt-get gets too annoying because due to pinning and mixing there is a lot of trouble I use aptitude.
By coincidence I looked at the help section of the command (doesn't happen often, thanks zsh) and look what I saw:
That kind of reminded me of this here:
Did you know those things and April's jokes already? Well if you have something more on the commandline like this, please let me know!
Cheers!
Linux Kernel exploit for 2.6.17 up to 2.6.24.1
February 11th, 2008
Today I encountered some serious exploits floating around in Full disclosure, Bugtraq and even Slashdot.
Better monkey patch your multiuser machines fast, before the script kiddies get a grip on this...
- LKML about this issue
- Slashdot Article
- Debian Bugtrack about this exploit
- Live Memory fix, which inserts a ret at the beginning of vmsplice()
- Full exploit POC
[0:07][br@gemini:programming/linux/exploits]% ./exploit ----------------------------------- Linux vmsplice Local Root Exploit By qaaz ----------------------------------- [+] mmap: 0x0 .. 0x1000 [+] page: 0x0 [+] page: 0x20 [+] mmap: 0x4000 .. 0x5000 [+] page: 0x4000 [+] page: 0x4020 [+] mmap: 0x1000 .. 0x2000 [+] page: 0x1000 [+] mmap: 0xb7f9e000 .. 0xb7fd0000 [+] root bash: 0STY: command not found root@gemini:~/programming/linux/exploits# whoami root root@gemini:~/programming/linux/exploits#
Beware of the live memory fix as some people experienced memory faults and system breakdowns.
[0:13][br@gemini:programming/linux/exploits]% ./disable_exploit ----------------------------------- Linux vmsplice Local Root Exploit By qaaz ----------------------------------- [+] mmap: 0x0 .. 0x1000 [+] page: 0x0 [+] page: 0x20 [+] mmap: 0x4000 .. 0x5000 [+] page: 0x4000 [+] page: 0x4020 [+] mmap: 0x1000 .. 0x2000 [+] page: 0x1000 [+] mmap: 0xb7fa8000 .. 0xb7fda000 [+] root Exploit gone! [0:14][br@gemini:programming/linux/exploits]% ./exploit ----------------------------------- Linux vmsplice Local Root Exploit By qaaz ----------------------------------- [+] mmap: 0x0 .. 0x1000 [+] page: 0x0 [+] page: 0x20 [+] mmap: 0x4000 .. 0x5000 [+] page: 0x4000 [+] page: 0x4020 [+] mmap: 0x1000 .. 0x2000 [+] page: 0x1000 [+] mmap: 0xb7f7c000 .. 0xb7fae000 [-] vmsplice [0:14][br@gemini:programming/linux/exploits]% whoami br
Update:
For more indepth analysis of what has been going on why, what, etc. find a nice LWN article here.
Veoh and the 5 minute limit
November 13th, 2007
I am a big fan of those Web 2.0 mashups like Youtube, Veoh, Divx Stage 6 and so on.
Recently Veoh cut back the playtime of their videos down to 5 minutes if it exeeded 20 minutes in total. Their main goal here was to propagate their ,,Veoh TV Player''. Well after a quick try with my Wine (yes, there is no Linux version available) I gave that idea quickly up and continued to search a bit.
Seems as there are still means to get the video out of their cache. Originally this little hack was introduced here which gave me the incentive to write the following little script. Lets say you want to watch some CCC Videos without playing around with Google webbits. For instance here is a video about Botnet Detection and Mitigation which is quite interesting but again it's limited to 5 minutes due to its longer duration.
First, we need to extract the permalink ID which is the last part of the URL - here it would be
,,v262945dCjc4CJs''. Utilizing this we can extract the original video hash and extension via this nifty trick.
Just call this URL - http://www.veoh.com/rest/video/PERMALINKID/details with the permalink ID embedded into it to get necessary values. There we can find the necessary data to complete this URL - http://p-cache.veoh.com/cache/external/ORIGINALHASHORIGEXTENSION - which actually points to a downloadable video file. Nice !
Lets see how the final script works...
% ./Downloader.rb http://www.veoh.com/videos/v262945dCjc4CJs
--01:13:35-- http://p-cache.veoh.com/cache/external/1df8cd077cde7650567d07e11e8e3ecfba1d3327.mp4
=> `1df8cd077cde7650567d07e11e8e3ecfba1d3327.mp4'
[..]
So much for that problem :)
Here the little Ruby script:
% cat Downloader.rb
#!/usr/bin/ruby -w
#
# (c) 2007, Bjoern Rennhak
# Ideas originally taken from http://board.alluc.org/viewtopic.php?pid=400997 .
#
# This code is released under GNU GPL v2.
#
require 'net/http'
require 'rexml/document'
( puts "Usage: #{$PROGRAM_NAME} [Veoh Permalink ID | Full URL]" and exit ) if( ARGV.empty? )
( ARGV[0] =~ %r{^http}i ) ? ( pLinkID = ARGV[0].gsub(/.*\/(.+)$/,'\1') ) : ( pLinkID = ARGV[0] )
detailsURL = "http://www.veoh.com/rest/video/#{pLinkID}/details"
xml = Net::HTTP.get_response( URI.parse(detailsURL) ).body
( REXML::Document.new(xml) ).elements.each('videos/video') do |e|
@origExtension, @originalHash = e.attributes['origExtension'], e.attributes['originalHash']
end
`wget http://p-cache.veoh.com/cache/external/#{@originalHash}#{@origExtension}`
I wrote it with clarity in mind so I am sure you can golf it shorter. :)
For you people out there who are into shell oneliners, here is one...
% awk -v id=v262945dCjc4CJs -- '{ system("lynx -dump http://www.veoh.com/rest/video/"id"/details"); exit }' | egrep "origExtension|originalHash" | xargs | sed 's!.*=\(.*\) .*=\(\..*\)!wget http://p-cache.veoh.com/cache/external/\1\2!g'
Firefox Memory Fragmentation
November 12th, 2007
In my daily work I browse a lot. Often I need the net as a big reference manual for many problems I encounter or even just for the daily news. Well, sometimes (or almost always) I end up with more tabs than I actually can manage to read a day.
Now is that not particularly bad as I always keep my workstation running anyways and as a bonus I can continue where I left off my work the following day. Oh, by the way did I mention that my workstation is a dual Xeon (HT) 3.06 Ghz machine with 2.0 GB RAM ? Well, that is one strong machine for such a puny task ! ,,What's your problem'' you probably ask ?
Funny^W thing is that the very next day my System behaves like a good old 486DX and it is utterly impossible to work on the machine. I figured after poking around a bit in the machine that something is really wrong with Firefox. This Article here explains a lot.
It's is pretty sad though if you see an entire 2.0GB of RAM used up by just a couple of browser instances. Hope they can fix it soon, but for now I am off using Opera as I have no time for something that doesn't work.
Here some data which I took at the time...
% vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
3 0 3559244 57068 113760 64044 0 1 1 10 9 4 8 4 87 0
% cat /proc/cpuinfo | grep -i "model name"
model name : Intel(R) Xeon(TM) CPU 3.06GHz
model name : Intel(R) Xeon(TM) CPU 3.06GHz
model name : Intel(R) Xeon(TM) CPU 3.06GHz
model name : Intel(R) Xeon(TM) CPU 3.06GHz
% cat /proc/meminfo| egrep -i "total|cache"
MemTotal: 2076420 kB
Cached: 65052 kB
SwapCached: 179096 kB
HighTotal: 1179092 kB
LowTotal: 897328 kB
SwapTotal: 4194296 kB
VmallocTotal: 114680 kB
% top -b | head -20
top - 15:01:30 up 11 days, 20:02, 10 users, load average: 0.97, 1.06, 0.98
Tasks: 233 total, 2 running, 231 sleeping, 0 stopped, 0 zombie
Cpu(s): 8.5%us, 3.9%sy, 0.0%ni, 87.2%id, 0.0%wa, 0.2%hi, 0.1%si, 0.0%st
Mem: 2076420k total, 2020036k used, 56384k free, 114396k buffers
Swap: 4194296k total, 3566232k used, 628064k free, 66248k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
15956 br 16 0 3058m 1.0g 8876 R 65 52.4 3147:09 firefox-bin
10117 root 15 0 1842m 348m 3348 S 16 17.2 2555:40 Xorg
1 root 15 0 2072 612 584 S 0 0.0 0:02.04 init
2 root RT 0 0 0 0 S 0 0.0 0:11.84 migration/0
3 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/0
4 root RT 0 0 0 0 S 0 0.0 0:00.44 migration/1
5 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/1
6 root RT 0 0 0 0 S 0 0.0 0:00.10 migration/2
7 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/2
8 root RT 0 0 0 0 S 0 0.0 0:00.20 migration/3
9 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/3
10 root 10 -5 0 0 0 S 0 0.0 0:01.14 events/0
11 root 10 -5 0 0 0 S 0 0.0 0:00.41 events/1
% top -b | egrep -i "firefox|%CPU"
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
15956 br 15 0 3058m 1.0g 8876 R 51 52.4 3147:40 firefox-bin
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
15956 br 15 0 3058m 1.0g 8876 R 69 52.4 3147:42 firefox-bin
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
15956 br 16 0 3058m 1.0g 8876 R 60 52.4 3147:44 firefox-bin
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
15956 br 15 0 3058m 1.0g 8876 R 67 52.4 3147:46 firefox-bin
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
15956 br 15 0 3058m 1.0g 8876 R 63 52.4 3147:48 firefox-bin
% pkill firefox-bin
% vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 397416 1610484 114976 75584 0 1 1 10 9 6 8 4 87 0
% *wow* i really need to change my browser :///
Thank you Linux 2.6.8-2
August 9th, 2007
On non critical systems back here some Linux Kernels may run for a longer time. Particularly one long running machine had to be taken down because of Hardware maintenance and needed VServer and Xen Kernel extensions.
[06:48][root@zeus:/]# uname -a Linux zeus 2.6.8-2-386-br #1 Thu May 19 17:40:50 JST 2005 i686 GNU/Linux [06:48][root@zeus:/]# uptime 06:49:00 up 677 days, 9:46, 1 user, load average: 0.28, 0.29, 0.29
Bye bye and thank you very much ! 0 commentss »
VMWare on strike
June 7th, 2007
Weird problem at work today ! After 297 days of fine uptime the VMWare instance on one machine crashed without any apparent reason. It got ,,funny'' after tickets started pouring in and VMWare gave me this answer while trying to restart the image.
Unable to change virtual machine power state: Failed to connect to peer process.
After a quick research on the net I found several possible solutions working on Debian GNU/Linux. Some of them pointed out that low disk space was the reason others wrong permissions.
Disk space was fine on my machine and permissions ? Come'on why should VMWare change that on the fly ? After a image backup and a chmod u+s vmware-vmx everything worked fine again.
Weird Software^W !