Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 616 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with Regular Expressions

#1
Regular expressions can be a very useful tool in your arsenal when creating hacking tools. You should use regular expressions when split just won't cut it. You would normally use String.Split when there is only one occurrence of a string in the block your searching. Regular expressions is great for finding specific strings in a block of text, and it can be MUCH faster.

You can use

[To see links please register here]

to help create your regular expression, it's what I normally use. I will go over a short intro to help get you started when creating a regular expression.

Match a single digit
\d

Match multiple digits
\d+

Match X amount of digits (if you want 3 digits; {3})
\d{x}

Match a single character
\w

Match any character or digit

.

Match any digit or character multiple times
.+

Match zero or more
?


So as an example, let's open the cracked.to website and view the source. We are going to use them as an example on how to scrape stuff. Let's scrape usernames and ID's.

Around line 2955 you will start to see the usernames

[Image: 49BbH4T.png]

So copy that and paste it into the bottom textbox on regex101. The top box is where we will begin to write our regex. Each entry is an anchor link which has the username and their ID.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


In the top box put the following expression


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Which should match that user (if they are logged in)

[Image: SBX9fpy.png]

On the right in the image above you can see that we matched it. However, we only matched that one entry and we want them all. So now, let's replace the name and id with a regular expression.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


So now let's turn this into something we can use in C#. You will need to include the RegularExpression namespace (

[To see links please register here]

). You can do that by adding the following line to the head of your code


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


We are going to read a text file that has the source of the main cracked.to website, so we don't leave a footprint on their site while working with the regular expression demo. You can download the source

[To see links please register here]

(

[To see links please register here]

). We can read the file using the File.ReadAllLines() method. We will need to add the System.IO namespace for this.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


So now let's apply our expression to the file we read above. Since the file we are using as a test is much different than how the source looks in your browser (in my case, Chrome) we are going to have to change our expression. Below is the image of the block of text on which we are going to use the expression.

[Image: VzI1mcp.png]

Create a new Regex Object

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Get the matches with MatchCollection

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.



Now we can loop through the matches in the MatchCollection, showing the capture groups. The capture groups is the data in parenthesis in the regular expression.



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


[Image: vhrK4py.png]
Reply

#2
nice tutorial :smile:! There are some websites to test regular expressions, I find them very useful when working with reg expr
Reply

#3
Thanks for the tutorial,
I would like to share this site:

[To see links please register here]

I use that site when writing regular expressions, it's very helpful
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through