Saturday, February 7, 2009

watchShutdownLogs.pl

I wrote this little script that really helps with testing dynamic store loading:

INVOKE AS:
watch -n 2 --differences=cumulative 'perl /root/watchShutdownLogs'



#!/usr/bin/perl


@fileList = `find /usr/local/pi/hosting/data/*/config/shutdown.pinode.conf`;
foreach $x (@fileList)
{
$x =~ m/data\/(.+)\/config/;
$y = $1;
print "$y \n";

printFile($x);
print "\n";

}


sub printFile
{
my $filename = $_[0];

open( FILE, $filename ) or die "Can't open $filename : $!";

while( ) {
if (m/store/)
{print $_;}
}

close FILE;
}

Tuesday, January 13, 2009

c++: const pointer and pointer to const

For pointer and reference types, the syntax is slightly more subtle. A pointer object can be declared as a const pointer or a pointer to a const object (or both).

A const pointer cannot be reassigned to point to a different object from the one it is initially assigned, but it can be used to modify the object that it points to (called the "pointee"). (Reference variables are thus an alternate syntax for const pointers.)

A pointer to a const object, on the other hand, can be reassigned to point to another object of the same type or of a convertible type, but it cannot be used to modify any object.

A const pointer to a const object can also be declared and can neither be used to modify the pointee nor be reassigned to point to another object.

The following code illustrates these subtleties:

void Foo( int * ptr, int const * ptrToConst, int * const constPtr, int const * const constPtrToConst )
{ 
    *ptr = 0; // OK: modifies the pointee

    ptr = 0; // OK: modifies the pointer

    *ptrToConst = 0; // Error! Cannot modify the pointee

    ptrToConst = 0; // OK: modifies the pointer

    *constPtr = 0; // OK: modifies the pointee

    constPtr = 0; // Error! Cannot modify the pointer

    *constPtrToConst = 0; // Error! Cannot modify the pointee

    constPtrToConst = 0; // Error! Cannot modify the pointer 
}
source

Friday, October 31, 2008

windows: removing the welcome/login screen in xp for single user logon

To log in automatically, type this command (it's a shortcut to 'User Accounts'):

control userpasswords2


Click the desired user's logon name, then click OK and enter the password when prompted (which is probably a blank).


To set the password for the current user to a blank, get to a cmd prompt and run this command:
net user "%UserName%" ""{Enter}



source

Friday, October 3, 2008

web security: input validation attacks

The following are some common input validation attacks;
• Path or directory traversal This attack is also known as the “dot dot slash”
because it is perpetrated by inserting the characters “../” several times into a URL
to back up or traverse into directories that weren’t supposed to be accessible from
the Web. The command “../” at the command prompt tells the system to back up
to the previous directory (try it, “cd ../”). If a web server’s default directory was
“c:\inetpub\www”, a URL requesting http://www.website.com/scripts/../../../../../
windows/system32/cmd.exe?/c+dir+c:\ would issue the command to back up
several directories to ensure it has gone all the way to the root of the drive and
then make the request to change to the operating system directory (windows\
system32) and run the cmd.exe listing the contents of the c: drive.
• Unicode encoding Unicode is an industry standard mechanism developed
to represent the entire range of over 100,000 textual characters in the world as
a standard coding format. Web servers support Unicode to support different
character sets (like Chinese), and, at a time, many supported it by default. So,
even if we told our systems to not allow the “../” directory traversal request
mentioned earlier, an attacker using Unicode could effectively make the same
directory traversal request without using “/”, but with any of the Unicode
representation of that character (three exist: %c1%1c, %c0%9v, and %c0%af).
That request may slip through unnoticed and be processed.
• URL encoding If you’ve ever noticed that a “space” appears as “%20” in a URL
in a web browser (Why is it only me who notices that?), the “%20” represents
the space because spaces aren’t allowed characters in a URL. Much like the
attacks using Unicode characters, attackers found that they could bypass filtering
techniques and make requests by representing characters differently.


source: http://www.amazon.com/gp/blog/post/PLNK225DWOGWJIEBG

Tuesday, September 30, 2008

HTTP: digest auth example

This "HTTP Digest Authentication" example from wikipedia was just too good. I had to post this here - a real collector's item! ;)


Step 3 has the crucial part of the whole process - the inclusion of the server's nonce into the MD5 hash computation, which refutes replay attacks.



1 . Client request (no authentication):


GET /dir/index.html HTTP/1.0
Host: localhost



2. Server response:



HTTP/1.0 401 Unauthorised
Server: HTTPd/0.9
Date: Sun, 10 Apr 2005 20:26:47 GMT
WWW-Authenticate: Digest realm="testrealm@host.com",
qop="auth,auth-int",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
Content-Type: text/html
Content-Length: 311


"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">





401 Unauthorised.





3. Client request (user name "Mufasa", password "Circle Of Life"):

GET /dir/index.html HTTP/1.0
Host: localhost
Authorization: Digest username="Mufasa",
realm="testrealm@host.com",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri="/dir/index.html",
qop=auth,
nc=00000001,
cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1",
opaque="5ccc069c403ebaf9f0171e9517f40e41"


4. Server response:

HTTP/1.0 200 OK
Server: HTTPd/0.9
Date: Sun, 10 Apr 2005 20:27:03 GMT
Content-Type: text/html
Content-Length: 7984



(source: http://en.wikipedia.org/wiki/Digest_access_authentication)

web security: nonce

Nonce (wrt HTTP digest authentication)
    
A nonce is a parameter that varies with time. A nonce can be a time stamp, a visit counter on a Web page, or a special marker intended to limit or prevent the unauthorized replay or reproduction of a file.

Because a nonce changes with time, it is easy to tell whether or not an attempt at replay or reproduction of a file is legitimate; the current time can be compared with the nonce. If it does not exceed it or if no nonce exists, then the attempt is authorized. Otherwise, the attempt is not authorized.