How to Program in C# : Introduction to the Basics (Part 1)

Introduction to the Basics (Part 1)

How to Program in C# : Introduction to the Basics (Part 1)

Welcome my aspiring hackers and programmers!

Today i will introduce you to a programming language that as a hacker you should have in your set of hacking/programming skills (except if you're only interested in web hacking/programming...then you should go learn some html or PHP instead of C#).

Let's start!!
First...let me brefly introduce the history of this language.
C# (pronounced C Sharp)...it's a programming language developed by Microsoft for its .NET framework in the early 2000.
(Very brief intro... I know, right?)

So...I will be using Xamarin Studio for Windows in the series of How Tos (you can find it here. You will have to fill in some infos about you). If you want to program in C# on Linux then you have 2 options:

1) Use whatever text editor you like and then save the file with the .cs extension

2) Download MonoDevelop which is a Linux version of Xamarin (go over this page and follow the instructions to install it or leave a comment if you want me to make a tutorial on how to install it)

Let's start coding :D!!
Now let's launch Xamarin and let's create a new Solution

Then let's select Console Project

And now let's choose a name for our project and a slightly different name for our Solution (in case we'll have multiple projects in the same Solution directory)

Don't forget to check the "Create a project within the solution directory box"

There you go!
Now you created a project that you don't understand...yet ...Great!!!!!

Mine has different colors than yours because i changed them because of the too much brightness of the white color scheme...no big deal (if you want to know how to change color scheme just ask in the comments).

If you're new to programming you have to understand that learning a programming language it's done step by step with very small steps...so sit comfortable because we have a long way to go and most important everything i will show you , you will have to type it too because programming isn't something you're going to learn by just reading.

With that said...let's move on!

For now we're only going to focus on the code in the curly brackets after the public static void Main line just keep it simple for now.Just keep in mind that class and namespaces are a way to keep things organized.

Ok...so...First of all remember that C# is case sensitive , so capitalization is important.

The first thing we're going to do is press on the play button in the top left corner of Xamarin , that's what we use to test the code that we wrote. You're going to notice that if you hit play that's only going to show a window appear and disappear very quickly...We can avoid that by telling the program to wait for us to type something before closing and we do that by typing:

Console.ReadKey ();
just under
Console.WriteLine ("Hello World");

Basically the word Console tells the System to WriteLine (write) what we tell him (in this case Hello World!) between the parentheses () and closing the line with the ";"

Easy right?
Ok so you now know how Console.WriteLine and Console.ReadKey "work".
For length reasons i'm going to stop this How To here but don't worry
i'll be back very soon to continue programming with you in C# !!
In the next How to I'll talk about Variables!!

Thanks for reading

ThE-F1XeR

35 Comments

True,a hacker must know how to c#,this must actually be the first thing before scripting viruses

Hmmm....i don't know if you noticed but this is a C# tutorial not C++ XD

oh i just realised i wrote c++ instead..my mistake.

I really love C# but I only see it suitable for programming business applications. Could you explain why you think it is essential for hacking or what benefits it has over other programming languages?

I agree with this. I don't think C# is useful to a hacker except making some kind of phishing application.

-Phoenix750

C#, is not directly useful to an hacker except for , as you said, phishing applications or some game hacks (like aimbots or ESP) but it is useful to build the "tool" itself that you'll later be using to hack or to help accomplish the "task"

About aimbots and ESP I wouldnt agree. They are better written in C++ because its faster than C#.

well true it's not useful but you must understand the idea of programming so you can understand hacking.

So Phoenix what do you think?
Should i continue this series?

I know your question was directed to Phoenix but I still want to give my two cents:
If you enjoy writing these, continue.

As a hacker, you can do nothing wrong learning a new programming language. And it's not like C# is completely useless for hackers.

I once wrote a worm-like Keylogger in C#. And the .NET Framework has a lot to offer for exploiting Windows-systems.

I second this.

-Phoenix750

My code for my botnet is made with c#, because it is easier to code in and the exe's are tiny.

I use twitter as the C&C, loading html content using c/c++ is manual(GET requests and deal with sockets) unless using curl library, whereas c# lets me do that in one single line of code.

Apparently null-byte slowly becomes a programming languages tutorial site, like many others, or did i miss something in that code related to ethical hacking? No? Oh, never mind, probably the author will post something meaningful in his next tutorial, you know, the one about variables...

Stop supporting this stupid basic tutorials with programming languages, there is enough junk around here!

Oh i'm sorry sir...i gotta say that you really are a big contributor to this community seen you're high number of posts (sarcasm)...by the way if OTW or any relevant member will find this series "junk" then they can go ahead and tell me and/or remove the post

Anyway sir i think, and i'm sure that there's people around here that can confirm it, a hacker need to know at the very least 1 programming language if you don't want to end up as a script-kiddie

How many times have read my comment? Once?

Read it again and read it until you get my message because it's clearly that you didn't get it! I agree that a hacker should know as much programming languages as possible, but this forum isn't a place for those stupid "How to declare a variable" or "How to do a while loop (insert programming language here)" tutorials. Why? Because its a fucking ethical hacking forum! If you don't know how to declare a stupid variable in (insert programming language here), then you are in the fucking wrong place! There already a bunch of such kind of tutorials all over you favorite search engine!

And about your sarcasm, since when someone with an account on this forum is obligated to post something? Or should i copy the code generated by the IDE i am using and post it here? Will this be a contribution? Will this raise someone's hacking skills? Yeah sure it will, lets all post that, it will be fun reading those 5 lines of code tutorials! Junk!

Do you really want to contribute on this forum? Then make a fucking scenario! A what? A scenario! You know... when you pretend that you have been employed by some corporation to test their security! Where you explain about attack vectors, exploit discovery, network enumeration and most important reporting your findings! Why? Because it's what ethical hackers do!

listen son,i don't want to argue,but as long as this had to do with hacking then it's good.If you don't like it just don't comment,or don't watch.

What exactly in those 5 lines of code is related to hacking? Please, enlighten me. I am by no means a hacker, i'm here to learn, like the most of the people here, so maybe i don't understand what exactly makes this post an ethical hacking tutorial!

Well, aren't you a special snowflake.

There are hundreds of Skiddies on this board posting stuff like "How can I hack X?" or "How to hack someone's email account?" or "Hack XY not working".

And you are complaining about someone actually bringing content to this site?

Hacking is a mindset of learning. Hacking is about understanding technology. Both of this criteria are fulfilled in this post.

And if you need an example for how to use C# for "(ethical) hacking purposes": Reverse Engineering.

Here is part of the description of Null Byte from the front page:

We're going to take it from ... to programing, ...

If you don't understand any of this, don't worry, this is the place to begin!

Now please stop making such a ruckus on an article from which time and effort was spent for a good purpose and take it somewhere else where you aren't destroying a place of education and disrupting others' learning.

Thank you.

It wasn't my intent to destroy this post, i just wanted to make a point. Apparently i failed to do so, even more, i managed to upset the author and some of the visitors of this post with my criticism and i'm sorry for that!

I really hoped that the visitors of this post will get my message and will support me, but apparently i expected to much. So that's why i'll brake down my first comment into a nice list, for all the special people here:

  1. Drop the basic programming tutorials, i.e. how to declare variables, condition, loops, function/methods. Because there are already a bunch of such kind of tutorials all over the internet and null byte doesn't need that, it will make navigating the forum harder and might give false expectations! Note that i didn't said to drop programming tutorials altogether.
  2. As a visitor of this forum, i expect to see tutorials oriented to ethical hacking, i.e. enumeration, vulnerability discovery, exploiting and most critical thing reporting your findings in a nice, readable form that anyone can understand! I know that most of this are covered by OTW, but that's the problem! If you want to learn something new, you have to study it from different points of view, i.e. different authors!
  3. A personal preference, null byte should have some kind of post template, some rules to post this tutorials that will be pleasant to read and wont hurt my eyes. Some of the contributors don't event know to start a new sentence with an uppercase letter or that it should by a space after some punctuation marks and not before! It's like some teen that didn't pay attention in the grammar class tries to teach everyone else how to hack. It's a bad image for this forum!

I hope now it's more clear what i expect from this posts, if not, then apparently i'm in the wrong place.
Cheers!

I find it comical how you complain about other people's grammar in a sentence which, grammatically and contextually, doesn't sounds correct.

I also noticed your aversion to the lack of diversity of authors posting tutorials in relation to ethical hacking. Let me tell you that there is a plethora of authors with exceptional tutorials on this forum.

(In case you didn't get that, each word was a link.)

One last remark, people can post anything they desire on here, as long as it adheres to the practices prescribed on the front page, as already stated by dontrustme who, by the way, has an amazing security oriented programming series which you should check out, since that is clearly what you said you were looking for.

If that doesn't help you, I don't know what will. Maybe this? Jokes aside, you need to learn how to use the search function at the top of each WHT page. That will be your first step towards finding those great tutorials, buried in the depths of this forum and its countless newbie enquiries.

TRT

Just like you said...people is here to learn things...and i dont' know the way you sir learn how to "ethically hack" but the way i do is not just jumping straight ahead without any knowledge about programming languages...and by the way this the first of many posts about C#...i'll show how it is useful to an hacker later in this series

huh,maybe you should stop trying to be a smartass and appreciate what he's doing? programming language is the basic of hacking..it's clearly you have no idea..

I appreciate your support
Thank you !! :D

Hey, thanks for the contribution! Will you be going as far as covering Windows forms? I might need these tutorials for making some ransomware. >:)

Dont make ransomware, why would you do that, it is illegal and immoral, you are stealing money

Please provide evidence from my comment anything about stealing money or any other actions of illegal/immoral intent.

why else would you make ransomware?

For the sake of learning

C sharp is a great language, my first one, and so amazingly beautifull, clear and on responsible enviroment

as many other oop languages as as3,vb etc.

But do not disagree about the most superior language for hacking.

Hacking is not about the language but making something from nothing.

what u started is something amazing, just don't give attention to anyone trying to show off their lack of hacking skills.

Personally i found it very useful, and you got +1 from me..

Hacked by Mr_Nakup3nda

Thank you a lot for your support !

Indeed, I don't see why one shouldn't learn C#. I do however disagree with learning it instead of PHP, I mean, learn both. PHP is pretty often used by crappy programmers, who occasionaly find that True and False are equivalent:

php > if ((true == "foo") && ("foo" == 0) && (0 == false)) echo "yay!";
yay!

Also, considering the fact that php is still the most used scripting language in webdevelopment, I wouldn't advice people NOT to learn php.

Share Your Thoughts

  • Hot
  • Latest