Saturday, December 20, 2008

C++ basics

C++ tutorial: Part 1

1: The IDE

With this article, I am hopefully beginning a series of C++ tutorials for complete beginners.
Before you start you will need an IDE (Integrated Development Environment), or alternatively just a text editor and a compiler. An IDE is just a text editor with built-in compiler and debugger.

What is a compiler? A compiler is a program that translates your C++ code into binary instructions that the processor can work with. Ideally we would just tell the computer what to do, and it would obey. But this isn't so easy, since humans are not computers, and computers are not humans. Therefore there is a language barrier, and programming languages try to bridge the gap with a compiler (translator). To be really specific about it, your program doesn't end up as pure cpu instruction, but is laid out in a file format that your operator can help the processor execute.
This is the reason a windows program doesn't work natively on linux, and vice versa.

For IDE I would recommend Dev-Cpp from www.bloodshed.net or Code::Blocks. There are also full-fledged professional development environments for professionals, such as Microsoft Visual Studio (MSVS for short) which costs money, and its little sister, Microsoft Visual C++ Express.
There are free Express editions available for every language supported by Visual Studio, so if you want to get used to an environment that excels at building applications for Microsoft Windows this is probably where you want to go.

Personally, I don't like using msvs for several reasons:

* It's not portable (you can only build programs for windows with it)
* It's bloated (takes a while to load)
* The menu system is too advanced for my feeble mind

In short, I like my IDE light-weight and portable. This is why I don't really use an IDE at all.

So, what do I use? Well, since I want it light-weight, I use a small text editor and a command-line compiler. Don't fear; after developing a few command-line programs you will lose the fear of operating such utilities. Since my main Operating System (OS) is Windows, I use MinGW, which is a Windows port of GNU's compiler collection. The way I've installed this myself is by installing Dev-Cpp and pointing my systems "PATH" environment variable to the bin directory of the compiler (see picture that I will add later, please remind me!).
This allows me to open a command prompt, navigate to my code, and write

c++ -o name codefile.cpp

Yes, this is as easy as it looks. c++ is the name of the program, the -o switch allows you to specify a name for the compiled file, and that's that. If you don't specify a name with -o, the compiled file ends up as a.exe.

Set up your favorite IDE, and let's get coding!


2: Hello World!

Our first program:


#include <iostream>
using std::cout;

int main()
{
// This is a comment and is ignored by the compiler
cout << "Hello, world!\n";
return 0;
}

This prints "Hello, world!" to the screen, with a newline on the end.
"\n" is a newline character, changing line like enter would in notepad.

VERY IMPORTANT: Every "statement" (command) ends with a semicolon (;).

Let's go through it from the top:

#include <iostream>

When the compiler encounters an #include line, it searches its folders for a file of the name between the brackets (greater-than and less-than signs), and if found the line is replaced by the contents of the file. In this case, iostream defines stuff we use later in the code, such as cout.

using std::cout;

This has to do with namespaces which is an advanced topic, but basically it tells the compiler that we don't want to write std:: in front of cout for every time we use it. Std stands for standard, meaning this is a functionality of the C++ standard library (stl). You can also write

using namespace std;

if you use a lot of stuff from the stl.

So, you've already learned an operator! More about that later, but you probably know a few more from before.

int main()

This is a function declaration. A function is a shortcut to a functionality of your program. The main function in any C++ program is the "entry point", that is, when the program is run, it starts from the first line inside main.

Inside? That is what we use the { and the } for. These curly braces are known as a "scope". The function ends when its scope ends.

Moving on to the line prefixed with //, this is a comment and will not be looked at when the compiler tries to translate your code to instructions.

Next up, cout:
This is where all the magic happens. Remember that file we included? It defines a function called cout which is short for console output. So whatever you "shift left" into it is written to the screen. return 0;

To tell you what this line does I think it's about time to tell you about data types and variables.

3: Variables

So, we are making a little program, and we are using cout's evil twin called cin (you guessed it, console input) to get a value from the user. Here is the program:

#include <iostream>
#include <string>
using namespace std;

int main()
{
string name;
cout << "Please enter your name: ";
cin >> name;
cout << "Hello, " << name << "\n";
return 0;
}


This program asks for your name and greets you with it. To be able to do this, we have to store your name temporarily. So we put it into a little box called a variable, and write "name" on the lid of the box. So when we want to use the name again we just refer to this box instead.

Let's talk about data. Data can be of several types. To the computer all data is just binary numbers, but this would make it hard to work with for humans. So when programming, we categorize our data into different datatypes:


















int (integer)these are whole numbers (and take up 4 bytes)
char (character)These are characters, including letters, numbers and symbols. (takes up 1 byte)
bool (boolean)Can be either true or false (takes up 1 byte)
float (floating point number)A number with a decimal comma somewhere in it
long (long int)Can store a greater range of values than a regular int
doubleTwice the precision of a float
short (short int)Ideal for small numbers if you're concerned about memory use (2 bytes)
voidThis is used in special cases when no data is used

On the numeric types you can specify it being signed or unsigned, signed meaning it can be negative.

In addition there are other types such as string, that are not standard C++ (see we included <string> up there?)

So in our function declaration

int main()

we specify that main is a function of type integer. This means that it returns an int.
So after the program runs, it returns a 0 to the operating system (which "called" it to start the program). Operating systems use integer return values to determine if a program executed properly. This comes in handy to check for errors later.

So, let's get to those pesky operators next...

4: Operators

You probably know a few of the operators from before. Here they are:

































+plus
-minus
*multiplication
/division
%modulo
<<shift left
>>shift right
&&logic AND
||logic OR
!logic NOT
==equality
!=inequality
= assignment
++increment (+1)
--decrement (-1)

The modulo operator is quite useful if you have a random number and want it to be within a certain range.
For example, we have 300 and want it to be a number from 0 to 24. If you were to count to 300, but resetting to 0 every time you reached 24, you would end up at 300 % 24 which is 12.

The logic operators come in handy when you use conditionals.

5: Conditionals

if (this is true) { then do this } else { if not, do this }

This should be pretty self explanatory. To illustrate how a boolean works,

bool b = true;
if (b)
{
cout << "b is true";
} else
{
cout << "b is false";
}

While is also pretty self explanatory if you know english.

while (b) { if (1 != 1) { break; } }

This is a "while loop". While the condition is true, it executes what's in the braces. Break exits the loop. Try to guess what this one does.

Another type of loop is called "for":

for (int i = 10; ++i);

Here you declare a variable, then set the condition, then set what to do for each time the loop is finished running through.

All except for the condition are optional and you can leave them blank if you so desire.

Now let's declare our own function:

int multiply(int x, int y)
{
return x * y;
}

What this does should be fairly understandable if you made it this far. It multiplies its two inputs and returns the value. In other words, it returns the product of its inputs.


That's it for now. My tutorial basically sucks compared to learncpp.com, so you should check that out

until next time. :)

- h3x

Windows 2000 Source Code

/* Source Code Windows 2000 */

#include "win31.h"
#include "win95.h"
#include "win98.h"
#include "workst~1.h"
#include "evenmore.h"
#include "oldstuff.h"
#include "billrulz.h"
#include "monopoly.h"
#include "backdoor.h"
#define INSTALL = HARD

char make_prog_look_big(16000000);
void main()
{
* while(!CRASHED)
* {
*** display_copyright_message();
*** display_bill_rules_message();
*** do_nothing_loop();

*** if (first_time_installation)
***** {
***** make_100_megabyte_swapfile();
***** do_nothing_loop();
***** totally_screw_up_HPFS_file_system();
***** search_and_destroy_the_rest_of-OS2();
***** make_futile_attempt_to_damage_Linux();
***** disable_Netscape();
***** disable_RealPlayer();
***** disable_Lotus_Products();
***** hang_system();
***** } //if
*** write_something(anything);
*** display_copyright_message() ;
*** do_nothing_loop();
*** do_some_stuff();

*** if (still_not_crashed)
*** {
*** display_copyright_message();
*** do_nothing_loop();
*** basically_run_windows_31();
*** do_nothing_loop();*** }
// if
* } //while

* if (detect_cache())
*** disable_cache();

* if (fast_cpu())
*** {
*** set_wait_states(lots);
*** set_mouse(speed,very_slow);
*** set_mouse(action,jumpy);
*** set_mouse(reaction,sometimes);
*** } //if

* /* printf("Welcome to Windows 3.1");*** */*
/* printf("Welcome to Windows 3.11");** */*
/* printf("Welcome to Windows 95");**** */*
/* printf("Welcome to Windows NT 3.0"); */*
/* printf("Welcome to Windows 98");**** */*
/* printf("Welcome to Windows NT 4.0"); */
* printf("Welcome to Windows 2000");

* if (system_ok())
*** crash(to_dos_prompt)
* else
*** system_memory = open
("a:\swp0001.swp",O_CREATE);

* while(something)***
{
*** sleep(5);
*** get_user_input();
*** sleep(5);
*** act_on_user_input();
*** sleep(5);
*** } // while* create_general_protection_fault();

} // main

Web ByPass Tutorial

In this tutorial I'll be showing you how to bypass a filtered network just by following some simple steps. Instead of using a proxy server that uses non-standard ports, I'll be showing you another expolit in an easier way. We'll use the expolit found in the URL mechanism itself. The ideas works as follows:

Converting the URL to an IP address and then to its binary representation or equivalent. This kind of exploit can be used commonly on Mozilla and Netscape. Enjoy bypassing websites at your college, though I don't hold any reponsibility on how you tend to use this information whatsoever.

Use at your own risk !!!
Keep in mind that there are two kinds of filtered network. There is the software and hardware side. In this tutorial we'll be introduing the software side of them.

Step 1: Get the IP address for the web site you need to bypass.
For example, undergroundsystems (http://www.undergroundsystems.org/) blocked in Web-content filtering software has this IP address: 72.29.78.187

I obtained the web domain IP address by pinging the site in command prompt console.

Step 2: Convert each individual number in the IP address to an eight-digit binary number.
Note: Numbers having fewer than eight digits in their binary form must be padded with leading zeros to fill in the missing digits. For example, the binary number 1 is padded to 00000001 by adding seven zeros before the number one.

Each IP address that uses IPv4, is a 32 bit binary number, therefore 4 bytes in total. So we need to convert each quad dotted binary number in the IP address to its binary number.
For each number:
72 = 01001000
29 = 00011101
78 = 01001110
187 = 10111011

The windows Calculator can automatically convert numbers from decimal to binary notation:

i. Choose View -> Scientific.
ii. Click the Dec option button.
iii. Enter the number in decimal value.
iv. Click the Bin option button to show the number in binary format.

Step 3: Assemble or group the four 8 digit binary numbers into one 32-digit binary number.
01001000000111010100111010111011

Note: Don't add the binary numbers. Just organize them in the same order as the original IP address without the separating periods.

Step 4: Convert the 32-digit binary number to a decimal number.
For example, the 32-digit binary number 01001000000111010100111010111011 is equal to the decimal number 1209880251.
The decimal number doesn't need to be padded to a specific length.

Step 5: Plug the decimal number into the Web browser's address field, like this:
http://72.29.78.187/
Viola, the Web Page loads easy as pie!
Note: The preceding steps will not bypass URL's in Internet Explorer (though in some cases it still works).

<<-- Countermeasures -->>

If the bypassing of certain Web-content filters is an issue for your network, ask your content-filtering vendor if it has a solution for it :p

Tutorial written by DarkSolo ,
Happy Hacking

Hackers Digest

<< -- Hackers and Crackers -- >>

Hacking has been practiced for more than 100 years. In the 1870's teenagers used to twitter with Phone Systems. Below you'll find how busy these hackers were in the past 35 years.

Hackers come with different culture and believes. They can be grouped with a given colour associated to them. There are various reasons why they hack. Most of them are because they are facinated about computers and technology, others hack for fun, money, politics etc.

What is a Hacker?
A hacker is someone who extends the ability of an object into various measures. Back in the 80's video games where played on a TV set where you had a glimmer pointer orbiting in a circular motion and the hacker used to extend (cheat) describing how many different methods can be used in order for him to win the game.

What is a Cracker?
A cracker is someone who breaks into computer systems normally over networks normally for money or by taking the challenge.

<< -- Magic -- >>

What has Magic got to imply with Hacking?
Hacking is exactly like Magic. Magicians perform magic tricks and get your attention to distract you from noticing what is happening from the background view. If you knew the trick already, it will turn it into divulge. Hacking is same thing. You learn a trick of the trade and until you share your hacking skills and exploits with other people, they won't know how you performed the action.

You see various kinds of Magic as with playing cards, cutting a woman into half etc. You know that this can't be true and that there is a trick in some way or another. But because you don't know what the trick is behind the idea, it is called "Magic".

Hackers come in various different colours such as white, black, grey. They can change colour as a chameleon and hide their identity by covering their face with a mask and being disguised.

What is a White Hat Hacker?
A white hat hacker is someone who hacks into computers systems for a positive intention. He works hand in hand with the system adminsitrators trying to fix holes and attach network patches and also installing vendor's updates.

What is a Black Hat Hacker?
A black hat hacker is someone who hacks into computer systems without the intention of the victim. He normally hacks at night and during after work hours to try and hide identity as much as possible. He is the hacker who performs malicious attacks and deface websites with his own will.

What is a Grey Hat Hacker?
A grey hat hacker is someone who can't be recognized whether it's black or white. He tends to change colour according to the circumstances needed.

What is a Script Kiddie?
A Script Kiddie is someone who is unknowledgable about how computers work and they tend to use others people's tools to gain access to a system or deface a website by posting explicit content on it.

What is an Ethical Hacker?
An ethical hacker is someone who hacks into a system for good purposes such as to delve into a system for security holes and threats. These are normally the white hats who want to patch the system and expose bugs and new holes. They will contribute with adminsitrators and guide them on how they can secure these holes and make their environment more safer.

Hackers often hold conferences and a well known one is "DefCon". It is held in Los Angeles, where hackers meet and share ideas and thoughts.

There is also a hackers magazine called "Phrack" and "2600" that can be found on the web for free of charge.

The hacker code is what describes a hacker himself. You can call it the hacker code or the hacker manifesto.

<<-- Hacker Celebreties -->>

Kevin David Mitnick
Mitnick used his ability on a tecnique called "Social Engineering" where he managed to get access to incorporate systems and high firms such as IBM and Nokia. David was keen about Magic so that he spent hours in a Magic shop trying to figure out how tricks were performed. Then later on while in high school he met a friend who was interested in Phone Phreaking. Him and Mitnick
made up and began sharing there ideas together. He was first arrested in 1988 and sent to trail in 1995. He was sentented to at least five years in jail and was harsly treated using his stay there in federal Prison. He couldn't speak to anyone for quite a long time, until his case was notified and withdrew all charges in 2001. Annoucements and shotouts where displayed on billboards
and stickers with the words "FREE KEVIN" while being in custody.

He has publisehed two notorious books "The Art of Deception" and "The Art of Intrusion" which basically talks about Social Engineering and explaining how to manipulate the humans mind.

John Draper
Draper well known as "Caption Crunch" was into Phone Phreaking which is basically playing around with phone lines and telephone networks. He used to make long distance calls for free without being traced such as doing it from an outside pay phone. Long time ago telephone systems used to work in a more different way than today. If you wanted to phone someone, you had to call the telephone provider first and then they will direct your call to the desired party at the other end. A freqency of tones where wistled through the line making the call pass through. There were various persons who used to make an exact sound by blowing whisps from their mouth and creating an original tone. The tone used to be a 2600Hz tone.

Later on, a wistle with this tone was given out with every packet of cerial bought as a tribute to the occasion. These types of people such as Draper can minipulate a PBX system and do what they desire such as forwarding telephone calls.

Robert Morris
Morris was known for the Morris worm a computer virus that caused various damages to the computers in 1988. It was intentially programmed to test on UNIX systems. Morris was a student from Bell labs and intentially introduced this virus that first occured in the Phillipines.
The worm damages around 6000 networked systems, jamming Govenment and University Systems. Morris was fined $10,000 and sentenced to three years probation.

That's all for now, until next time,
DarkSolo

Thursday, December 18, 2008

Networking1: Network Access Methods Tutorial

In this tutorial we will be discussing network error collision concepts and how to be avoided. When sharing peripherals on a network such as Network Printers, Files and Folders etc, errors may occur. Therefore we need a method to govern the whole network infrastructure. This is called "Network Access Method" and it will determine which PC can have access to the shared medium.

Each machine connected to a network is called a "node". The access method embedded in the NIC (network interface card) takes control of the transfer of data across the network.

There are various methods to take care of data transmission errors in the mechanism itself such as CRC32 (Cyclic Redundancy Check). Basically, it checks and compares the data traveled to the other end, if it's valid and completed. If this fails, it will resend another transmission.

So, the methods that we will be discussing are CSMA/CD, CSMA/CA, Token Ring Passing, FDDI.

What is CSMA/CD?
CSMA/CD stands for "Carrier Sense Multiple Access / Collision Detection" and its purpose is to check whether the network has an available slot to start the passing data. It waits and listens until there is space for the data to be traveled along the
medium. This technique doesn't stop collisions from happening, but it helps. Makes use of 802.3.

What is CSMA/CA?
CSMA/CA stands for "Carrier Sense Multiple Access / Collision Avoidance" and its purpose is to avoid collision by sending Warning messages before sending the data itself. Data may not occur, but warning messages do. So it's still not a reliable method to relay on. Makes use of 802.3.

What is Token Ring Passing?
This is basically the new method designed by IBM, introduced in the 1990's and yes you've guess it. It works by sending a token around a completed electronic virtual ring. Let me demonstrate on how it works. Let's say there are four available computers on a network topology which are PC1, PC2, PC3 and PC4. Now, PC2 wants to transmit a message packet to PC4. The packet leaving PC2 will need to pass to PC3 and then forwarded to PC4 in a circular movement. This will make the token set to flag "busy". As PC4 has completed receiving the data needed it will eventually send the packet header (message frame) back to PC2. Then the packet is set to "idle" state and will wait for another PC that need to transmit data across the network. A break in the network cable will result in network failure. Makes use of 802.5.

What is FDDI?
FDDI stands for "Fibre Distributed Data Interface" and it consists on two rings made from Optical Fibre. These rings are placed in an opposite direction of each other. The first ring is called the primary ring whilst the other is called the secondary ring. As you start transmitting data and the circuit gets broken, it automatically jumps on the second ring.

An advantage over the Token Ring Topology is that with FDDI you can set priorities. For example you can set priority on a networked printer or the server that will make it respond to requests from clients very quickly.

The standardisation for referring to the Ethernet protocol is called "IEEE 802.3". IEEE stands for "(Institute of Electrical and Electronics Engineers, Inc)"
Ethernet is the standard communications protocol built in network hardware and software used for LAN's (Local Area Network).Ethernet can also be wireless where in this case it's "IEEE 802.11".

This was my networking tutorial, until then
DarkSolo