C Program to accept a password

This is a simple login program in C. While accepting password it masks each character using ‘*’ symbol and display the password in the next line after the user hits Enter key. It also accepts backspaces and acts accordingly.

#include
#include

char pw[25],ch;
int i;
void main()
{
clrscr();
puts(“Enter password”);
while(1)
{
if(i<0)
i=0;
ch=getch();
if(ch==13)
break; /*13 is ASCII value of ENTER*/
if(ch==8) /*ASCII value of BACKSPACE*/
{
putch(‘b’);
putch(NULL);
putch(‘b’);
–i;
continue;
}
pw[i++]=ch;
ch=’*’;
putch(ch);
}
pw[i]=’?;
printf(“nn%s”,pw);
getch();
}


Read Users' Comments (0)

This program will get or read the current system date from the system. It displays Year, Month and Day.

#include
#include

int main(void)

{
struct date d;
getdate(&d);
printf(“The current year is: %dn”, d.da_year);
printf(“The current day is: %dn”, d.da_day);
printf(“The current month is: %dn”, d.da_mon);
return 0;
}

Read Users' Comments (0)

C Program to display current date

This program can be used to set or change the system time

#include
#include

int main(void)
{
struct time t;
gettime(&t);
printf(“The current hour is: %dn”, t.ti_hour);
printf(“The current min is: %dn”, t.ti_min);
printf(“The current second is: %dn”, t.ti_sec);

/* Add one to the hour,minute & sec struct element and then call settime */

t.ti_hour++;
t.ti_min++;
t.ti_sec++;
settime(&t);
printf(“The current hour is: %dn”, t.ti_hour);
printf(“The current min is: %dn”, t.ti_min);
printf(“The current second is: %dn”, t.ti_sec);
return 0;
}

Read Users' Comments (0)

C Program to get Current Time

This program reads the current system time and displays it in the form HH:MM:SS

#include
#include

int main(void)

{
struct time t;
gettime(&t);
printf(“The current time is: %2d:%02d:%02dn”, t.ti_hour, t.ti_min, t.ti_sec);
return 0;
}


Read Users' Comments (0)

Guessing game in C

This is a small guessing game written in C. In this guessing game you have to guess a number between 0 & 100. You have 8 chances to do that. Every time you guess wrongly the program will give you a hint that your guess is too high or your guess is too low. Based on this hint you have to guess the number in the remaining attempts. Here’s thecode

#include
#include
#include

void main()

{
int num,guess=-1,tries=0,pass=0;
time_t t;
srand((unsigned)time(&t));
num=rand()%100;
while((guess!=num)&&tries<8)
{
printf(“Enter the guess num b/w 0 & 100 (you have %d tries left out)n”,(8-tries)); scanf(“%d”,&guess);
tries++;
if(guess==num)
{
printf(“Hurray you guessed it correctly!!!n”);
pass=1;
}
else if(num< guess)
printf(“Your guess is too highn”);
else
printf(“Your guess is too lown”);
}
if(pass==0)
printf(“Sorry you lost! The correct number is %dn”,num);
}

Read Users' Comments (0)

Self Destructing program in C

This program will destroy itself upon execution. The program will cause the .exe file to be deleted upon execution. That is this program is capable of destroying itself upon execution. Here is the code

#include
#include
#include
void main()
{
printf(“This program will destroy itself if u press any key!!!n”);
getch();
remove(_argv[0]);/*array of pointers to command line arguments*/
}

Read Users' Comments (0)

C Program without main function

How to write a C program without a main function?. Is it possible to do that. Yes there can be a C program without a main function. Here’s the code of the program without a main function…

#include
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)

int begin()

{
printf(” hello “);
}

Does the above program run without the main function? Yes, the above program runs perfectly fine even without a main function. But how, whats the logic behind it? How can we have a C program working without main?

Here we are using preprocessor directive #define with arguments to give an impression that the program runs without main. But in reality it runs with a hidden main function.

The ‘##‘ operator is called the token pasting or token merging operator. That is we can merge two or more characters with it.

NOTE: A Preprocessor is program which processess the source code before compilation.

Look at the 2nd line of program -

#define decode(s,t,u,m,p,e,d) m##s##u##t

What is the preprocessor doing here. The macro decode(s,t,u,m,p,e,d) is being expanded as “msut” (The ## operator merges m,s,u & t into msut). The logic is when you pass (s,t,u,m,p,e,d) as argument it merges the 4th,1st,3rd & the 2nd characters(tokens)

Now look at the third line of the program -

#define begin decode(a,n,i,m,a,t,e)

Here the preprocessor replaces the macro “begin” with the expansion decode(a,n,i,m,a,t,e). According to the macro definition in the previous line the argument must be expanded so that the 4th,1st,3rd & the 2nd characters must be merged. In the argument (a,n,i,m,a,t,e) 4th,1st,3rd & the 2nd characters are ‘m’,’a’,’i’ & ‘n’.

So the third line “int begin” is replaced by “int main” by the preprocessor before the program is passed on for the compiler. That’s it…

The bottom line is there can never exist a C program without a main function. Here we are just playing a gimmick that makes us beleive the program runs without main function, but actually there exists a hidden main function in the program. Here we are using the proprocessor directive to intelligently replace the word begin” by “main”. In simple words int begin=int main.

Read Users' Comments (0)

File Embedder in C

Some times it is necessary for our compiled project to have it’s supporting files embedded within the EXE module itself so that the supporting files may not be put into a seperate folder and carried along with the project. So here I am presenting you with the source code of the FILE EMBEDDER UTILITY project.

This utility can be used to embed one file with in the other. ie: Suppose we need to embed a .bat file(or any other file *.exe,*bmp,.txt…..) into our final project so that the batch file is present with in the compiled module and is hidden from the users avoiding tthe need to carry the .bat file every time with the project.

Both the Embedding and extraction process has been presented in seperate functions for your convenience. Here’s the code…..

#include
#include
#include
#include
#include
#include
#include

void embed(void);
void extract(void);

char buff[1],sname[128],tname[128],dname[128],choice;
unsigned long int size=0;long int psize=0;int outh,bytes=0;
FILE *source,*target,*data;

void main()
{
while(1)
{
clrscr();
puts(“nntttFILE EMBEDDING UTILITY BY SRIKANTHnnn”);
puts(“1.Embed A File 2. Extract A File 3.Exitn”);
choice=getch();
switch(choice)
{
case ’1?:embed();
getch();
break;
case ’2?:
extract();
getch();
break;
default:
exit(0);
}
}
}

void embed()
{
puts(“nEnter The Source Filenamen”);
scanf(“%s”,sname);
source=fopen(sname,”rb+”);
if(source==NULL)
{
puts(“nCannot Open The Source Filen”);
return;
}
puts(“nEnter The Target Filenamen”);
scanf(“%s”,tname);
outh=open(tname,O_RDONLYO_BINARY);
if(outh==-1)
{
puts(“nCannot Open The Target Filen”);
return;
}
printf(“nReading The Source File Please Wait…n”);
while((bytes=read(outh,buff,1))>0)
size+=bytes;
data=fopen(“Data.cfg”,”w”);
if(data==NULL)
{
puts(“nCannot Create Configuration The Filen”);
return;
}
fprintf(data,”%lu”,size);
close(outh);
fclose(data);
target=fopen(tname,”rb”);
if(target==NULL)
{
puts(“Cannot Open Target Filen”);
return;
}
printf(“nEmbedding Please Wait…n”);
fseek(source,0,SEEK_END);
while(fread(buff,1,1,target)>0)
fwrite(buff,1,1,source);
fcloseall();
printf(“nEmbedding Completed Successfullyn”);
}

void extract()
{
printf(“nEnter The Source Filenamen”);
scanf(“%s”,sname);
source=fopen(sname,”rb”);
if(source==NULL)
{
printf(“nCannot Open The Source Filen”);
return;
}
printf(“nEnter The Target Filename(eg: abc.exe)n”);
scanf(“%s”,tname);
printf(“nEnter The Configuration Filename(eg: DATA.cfg)n”);
scanf(“%s”,dname);
data=fopen(dname,”r”);
if(data==NULL)
{
printf(“nConfiguration File Not Foundn”);
return;
}
fscanf(data,”%ld”,&psize);
target=fopen(tname,”wb”);
if(target==NULL)
{
puts(“nCannot Open The Target Filen”);
return;
}
printf(“nExtracting Please Wait…n”);
fseek(source,-psize,SEEK_END);
while((fread(buff,1,1,source))>0)
fwrite(buff,1,1,target);
printf(“nFile Extraction Completed Successfullyn”);
fcloseall();
}


Read Users' Comments (0)

Private and Public IP Addresses

Internet Protocol (IP) addresses are usually of two types:Public and Private. If you have ever wondered to know what is the difference between a public and a private IP address, then you are at the right place. In this post I will try to explain the difference between a public and a private IP address in layman’s terms so that it becomes simple and easy to understand.

What are Public IP Addresses?

A public IP address is assigned to every computer that connects to the Internet where each IP is unique. Hence there cannot exist two computers with the same public IP address all over the Internet. This addressing scheme makes it possible for the computers to “find each other” online and exchange information. User has no control over the IP address (public) that is assigned to the computer. The public IP address is assigned to the computer by the Internet Service Provider as soon as the computer is connected to the Internet gateway.

A public IP address can be either static or dynamic. A static public IP address does not change and is used primarily for hosting webpages or services on the Internet. On the other hand a dynamic public IP address is chosen from a pool of available addresses and changes each time one connects to the Internet. Most Internet users will only have a dynamic IP assigned to their computer which goes off when the computer is disconnected from the Internet. Thus when it is re-connected it gets a new IP.

You can check your public IP address by visiting www.whatismyip.com

What are Private IP Addresses?

An IP address is considered private if the IP number falls within one of the IP address ranges reserved for private networks such as a Local Area Network (LAN). The Internet Assigned Numbers Authority (IANA) has reserved the following three blocks of the IP address space for private networks (local networks):

10.0.0.0 – 10.255.255.255 (Total Addresses: 16,777,216)
172.16.0.0 – 172.31.255.255 (Total Addresses: 1,048,576)
192.168.0.0 – 192.168.255.255 (Total Addresses: 65,536)

Private IP addresses are used for numbering the computers in a private network including home, school and business LANs in airports and hotels which makes it possible for the computers in the network to communicate with each other. Say for example, if a network X consists of 10 computers each of them can be given an IP starting from 192.168.1.1 to192.168.1.10. Unlike the public IP, the administrator of the private network is free to assign an IP address of his own choice (provided the IP number falls in the private IP address range as mentioned above).

Devices with private IP addresses cannot connect directly to the Internet. Likewise, computers outside the local network cannot connect directly to a device with a private IP. It is possible to interconnect two private networks with the help of a router or a similar device that supports Network Address Translation.

If the private network is connected to the Internet (through an Internet connection via ISP) then each computer will have a private IP as well as a public IP. Private IP is used for communication within the network where as the public IP is used for communication over the Internet. Most Internet users with a DSL/ADSL connection will have both a private as well as a public IP.

You can know your private IP by typing ipconfig command in the command prompt. The number that you see against “IPV4 Address:” is your private IP which in most cases will be 192.168.1.1 or 192.168.1.2. Unlike the public IP, private IP addresses are always static in nature.

Unlike what most people assume, a private IP is neither the one which is impossible to trace (just like the private telephone number) nor the one reserved for stealth Internet usage. In reality there is no public IP address that is impossible to trace since the protocol itself is designed for transperancy

Read Users' Comments (0)

Hack an Ethernet ADSL Router

Almost half of the Internet users across the globe use ADSL routers/modems to connect to the Internet however, most of them are unaware of the fact that it has a serious vulnerability which can easily be exploited even by a noobhacker just like you. In this post I will show you how to exploit a common vulnerability that lies in most ADSL routers so as to gain complete access to the router settings and ISP login details.

Every router comes with a username and password using which it is possible to gain access to the router settings and configure the device. The vulnerability actually lies in theDefault username and password that comes with the factory settings. Usually the routers come preconfigured from the Internet Service provider and hence the users do not bother to change the password later. This makes it possible for the attackers to gain unauthorized access and modify the router settings using a common set of default usernames and passwords. Here is how you can do it.

Before you proceed, you need the following tool in the process

Angry IP Scanner

Here is a detailed information on how to exploit the vulnerability of an ADSL router.

Step-1: Go to www.whatismyipaddress.com. Once the page is loaded you will find your IP address. Note it down.

Step-2: Open Angry IP Scanner, here you will see an option called IP Range: where you need to enter the range of IP address to scan for.

Suppose your IP is 117.192.195.101, you can set the range something as117.192.194.0 to 117.192.200.255so that there exists atleast 200-300 IP addresses in the range.

Step-3: Go to Tools->Preferences and select the Ports tab. Under Port selectionenter 80 (we need to scan for port 80). Now switch to the Display tab, select the option “Hosts with open ports only” and click on OK.

I have used Angry IP Scanner v3.0 beta-4. If you are using a different version, you need to Go to Options instead of Tools

Step-4: Now click on Start. After a few minutes, the IP scanner will show a list of IPs with Port 80 open as shown in the below image.



Step-5: Now copy any of the IP from the list, paste it in your browser’s address bar and hit enter. A window will popup asking for username and password. Since most users do not change the passwords, it should most likely work with the default username and password. For most routers the default username-password pair will be admin-admin or admin-password.

Just enter the username-password as specified above and hit enter. If you are lucky you should gain access to the router settings page where you can modify any of the router settings. The settings page can vary from router to router. A sample router settings page is shown below

If you do not succeed to gain access, select another IP from the list and repeat the step-5. Atleast 1 out of 5 IPs will have a default password and hence you will surely be able to gain access.

What can an Attacker do by Gaining Access to the Router Settings?

By gaining access to the router settings, it is possible for an attacker to modify any of the router settings which results in the malfunction of the router. As a result the target user’s computer will be disconnected from the Internet. In the worst case the attacker can copy the ISP login details from the router to steal the Internet connection or play any kind of prank with the router settings. So the victim has to reconfigure the router in order to bring it back to action.

The Verdict:

If you are using an ADSL router to connect to the Internet, it is highly recommended that you immediately change your password to prevent any such attacks in the future. Who knows, you may be the next victim of such an attack.

Since the configuration varies from router to router, you need to contact your ISP for details on how to change the password for your model

Warning!

All the information provided in this post are for educational purposes only. Please do not use this information for illegal purposes.

Read Users' Comments (1)comments

Free Ethical Hacking Workshop For All:- Fulfill Elegibility Criteria

Who should attend this workshop:-

Anyone Who is Interested in knowing more about Computer Security and Ethical Hacking. It doesn’t matter if you are a Computer Expert or a newbie, This workshop will have something for all.

Topics to be covered:-

Anything and everything you request before 22 June 2011.. Please don’t ask for any black hat hacking tricks or such stuff. We Deal only with White Hat hacking.

Where to request the topics?
Well Read on.. It is given at the end.
We Need 4 days to write blog posts about the topics you request.

Rules/ Eligibility criteria:-
Who can attend the workshop:-


Well you just have to do 5 things to attend the workshop.
1) Subscribe to http://learnhacking.in/
2) Send Invite to this event to all your FaceBook friends and share its link on your Fb wall as well.
http://www.facebook.com/event.php?eid=174297469295411/


3)Like the Fan page of Learn Hacking ie..
http://www.facebook.com/learnethicalhacking

4) Follow Learn Hacking on twitter

http://twitter.com/LearnHackingin/

2) Open Learn Hacking forum ie.. http://forum.learnhacking.in/ and under the topic named “Free Ethical Hacking Workshop” dated 26 June 2011 mark your attendance ie… write your name stating you are attending the workshop.
eg…” Alex – I am attending the Ethical Hacking Workshop”

NOTE:- All the above points will be verified before letting you attend the workshop.

How to Request the topics you want us to cover:-
1) Goto http://forum.learnhacking.in/
2) under the section “Free Ethical Hacking Workshop” goto the section “Request the topics you want us to cover” and request anything you want there.
3) We have decided some topics from our end as well.

And that’s it.
You just have to spare 5 minutes and fulfill the eligibility criteria.
You don’t have to pay us anything. Its 100% free of cost.

Note:- I will give you the provision to attend the event/ workshop only when you fulfill all the requirements ie.. the eligibility criteria.

This workshop is powered by innobuzz

ATTENTION:-

The best part of the workshop, we have very often discussed about the vulnerability / loophole in FaceBook security with our Friends.
We Will be discussing it in Detail. We will tell you how can any of your friend Hack your FaceBook account in less than 10 minutes and will also tell you the way to protect yourself..

Read Users' Comments (0)