Friday, December 26, 2014

Perfect online source control solution for freelancers

Bitbucket is free for teams of up to 5 users, uses both Git and Mercurial, comes with JIRA integration and has a great backup policy (also free) as well as a free and very usable GUI based client that makes source control tasks completely painless.

Monday, December 1, 2014

Great intro video to Windows HID development

Great intro video to Windows HID development

http://msdn.microsoft.com/en-US/library/windows/hardware/jj591517.aspx

Monday, October 27, 2014

SOCKS proxy client socket sample

I was shocked at the almost complete lack of online code samples for establishing connections through a SOCKS proxy with network sockets in C. SOCKS protocol is specified in RFC 1928.

Here is code I have used successfully to connect to a locally installed Tor SOCKS proxy:


fd = socket(AF_INET, SOCK_STREAM, 0);

if (fd < 0)
{
 exit(1);
}

struct sockaddr_in s;

s.sin_family = AF_INET;

s.sin_port = htons(9050);
s.sin_addr.s_addr = inet_addr("127.0.0.1");

eid = connect(fd, (struct sockaddr *) &s, sizeof s); //Connect to Tor Proxy
if (eid < 0)
{
 exit(3);
}

//SOCKS 5 protocol stuff starts here
////////////////////////////////////////////////////////////////////////////////////////////////
char sbuffer[256];
char *ptrBuff;

ptrBuff = sbuffer;

*(ptrBuff++) = 0x05;          //socks protocol version 5

*(ptrBuff++) = 0x01;          // supporting 1 auth method, 1) no auth 2) user pass auth

*(ptrBuff++) = 0x00;


send(fd, sbuffer, ptrBuff - sbuffer, 0);

recv(fd, sbuffer, 2, 0);

if (sbuffer[1] == 0xFF || sbuffer[1] != 0x00)
{
 exit(1);
}

ptrBuff = sbuffer;
*(ptrBuff++) = 0x05;      // socks version
*(ptrBuff++) = 0x01;      // sending CONNECT command
*(ptrBuff++) = 0x00;      // Reserved
*(ptrBuff++) = 0x03;      // address type - 1 for IPV4, 3 for domain name

char* dest_addr = "irc.whatever.com";

*(ptrBuff++) = strlen(dest_addr); //first byte records length of domain name string (without the terminating NULL)

memcpy(ptrBuff, dest_addr, strlen(dest_addr));
ptrBuff += strlen(dest_addr);

unsigned int dest_port = 6667;

*(ptrBuff++) = (dest_port >> 8); //port in network byte order - reverse lil endian bytes in int
*(ptrBuff++) = (dest_port & 0xFF);
 

send(fd, sbuffer, ptrBuff - sbuffer, 0);

recv(fd, sbuffer, 3, 0);

if (sbuffer[1] != 0x00)
{
 exit(2);
}

//////////////////////////////////////////////////////////////////////////////////
// From here on write/read from the socket as if you were directly connected to
// the desired server

Friday, September 12, 2014

Easily periodically refresh/restart a linux process

Easily periodically refresh/restart a linux process:



while [ 1 ]
do
timeout –s SIGKILL 3h mycommand myargs
done

Saturday, May 17, 2014

Run any program online

Sometimes you may need to compile and run a program real quick without having to setup compilers and IDEs on your box. For this purpose there is a number of sites that offer online program compilation and running for a host of programming languages.

I have used http://ideone.com/ and thought it works great. There are memory and processing time limitations (e.g. it would give me a memory error if I run a loop for more than 1K iterations) but for anything not overly heavy it will work fine.

Saturday, April 26, 2014

ffmpeg and RTSP over TCP streams

ffmpeg, by default, will first try to connect to a given input RTSP stream over UDP and then revert to TCP if there is no UDP response. Unfortunately this switch in the transport protocol is not handled very well and some devices (e.g. DVRs and IP Cams) fail to correctly send back the stream over TCP.

In this cases ffmpeg should be forced to TCP mode only like this:
ffmpeg  -rtsp_transport tcp -i "rtsp://whatever.com:554/user=xxxx&password=xxxx&channel=2&stream=0.sdp" -codec copy mydumpfile.mpg

Tuesday, March 25, 2014

Privoxy RegExs and OpenWRT

Do not assume that just because your Privoxy filters are working on regular Windows/Linux they will keep working on Privoxy for OpenWrt. Limited memory resources can cause certain involved/long RegEx patterns to exhaust it and cause Privoxy and/or OpenWrt crashes. Also, is you are using the "@" character instead of the usual "|" as delimiter in Perl style text substitution regexs do revert back to "|" as "@" is not supported and will also cause Privoxy and even OpenWrt to crash.

If you are doing script injection prefer to inject it through a secondary minimal boot-strap script (that creates a SCRIPT element in the document's DOM and adds the main script as SRC - the script source being served by some URL) rather than injecting it directly through your Privoxy filter configuration file.

Sunday, March 23, 2014

Ghost Javascript syntax error

Something like this will break javascript compilers although it is theoretically valid code:

function lala()
{
    var o;
    o.afunction=function()
    {}if(o) return;
}

I simplified it to get to the crux of the problem; putting a semicolon or a new line right before the "if" fixes it.

Thursday, March 20, 2014

Transcoding from unknown/undocumented Chinese H.264 DVR streaming protocol to RTMP

These are a couple of videos that I put together in order to inform on project progress a Brazilian client who wanted to transcode streaming H.264 video from a surveillance DVR brand to a media server accepting RTMP (Red5). I eventually got it to work perfectly of course! :)




Sunday, March 16, 2014

Red5 and Java installation

Red5 requires Java to work. Proper Java installation can give you a headache though. Yes, decades after Java was introduced its installation is still an issue quite often!

Here's my way to get it right (on Windows) without delving too much into the reasons of Sun/Oracle's inability to sort this out in so many years:
  • Find and uninstall all Java related entries in "Uninstall a Program" (Control Panel)
  • Remove any related environment variables like CLASSPATH, JAVA_HOME, JRE_HOME and QT_JAVA
  • Also uninstall Red5 if it is already installed
  • Download the latest 32-bit JDK from the Oracle site and install it - make sure you install the JRE version that comes with it (the 64-bit version of the JDK is rarely needed and is mostly incompatible with software that requires Java, including Red5; therefore only install it if ABSOLUTELY needed or you may run into complications and trouble)
  • Now install Red5 and input "127.0.0.1" and "5080" in the two dialog popups that come up at the end of the installation.
  • You should now be able to start the Red5 windows service without problem
  • In case it still does not start, set both JAVA_HOME and JRE_HOME to "C:\Program Files (x86)\Java\jre7" and try again.

Tuesday, March 11, 2014

Over 1 Billion USD earned on Elance

https://www.elance.com/q/blog/well-done-elancers-over-1-billion-earned-elance

Monday, March 10, 2014

End of Windows XP era


Microsoft is ending support for the Windows XP operating system and Office 2003 product line on April 8, 2014. After this date, these products will no longer receive:
  • Security patches which help protect PCs from harmful viruses, spyware, and other malicious software
  • Assisted technical support from Microsoft
  • Software and content updates
Good bye Win XP! You have been a good OS.

Sunday, March 9, 2014

Amazon & eBay reselling

There is a lot of demand for automatically scraping Amazon listed items, re-listing them on eBay (and vice versa) and making a customizable profit in-between.

Amazon's terms of service (ToS) prohibit this so currently re-sellers are focusing on hiring people who can defeat their detection methods. It is an on-going struggle of course which is good for us IT Security specializing contractors.

Quite interesting to contemplate and execute.

Monday, March 3, 2014

Mini-dump vs full-dump

The difference between a mini-dump and a full-dump is more related to the format of the file than the amount of content/information in it. In fact, with the right configuration, a mini-dump will contain more information than a full-dump ever could and that is why properly configured mini-dumps are recommended in all cases.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff552212%28v=vs.85%29.aspx

Chrome v.33 and extensions installation


As of Chrome v.33 (introduced 2014-02-20) extension installations through Windows registry entries pointing to local crx files are not supported any more. The crx file has to reside on the Chrome web store.

The Chrome security updates just implemented were foreshadowed in this communication: http://blog.chromium.org/2013/11/protecting-windows-users-from-malicious.html

Sunday, March 2, 2014

Barcode scanners and LAMP

It seems that today many inventory control barcode scanners are simply WiFi connected devices accessing a LAMP stack managing the inventory database

http://stackoverflow.com/questions/2900010/php-and-barcode-scanners