viernes, 19 de enero de 2024

Smart Contract Hacking Chapter 1 - Solidity For Penetration Testers Part 1 (Hello World)

 

Note: We will start off our Smart Contract Hacking journey with some basic solidity programming in the first two weeks. After that we will ramp things up and get a little crazy deploying blockchains and liquidating funds from accounts. But since the purpose of this series is to share the information I have learned over the last two years.  I do not want to alienate those new to Smart Contracts and programming so we will take these first few weeks a bit slow. 

Also note the text was taken from a book I was / am writing, I retrofitted it for this blog, and placed videos where screenshots may otherwise exist. If something seems off.. Just DM me on twitter and I will update it anything I might have missed during editing, but I tried to edit it as best as possible to meet this format rather then a book. 

Cheers  @Fiction 

http://cclabs.io

Thanks to @GarrGhar for helping me edit/sanity check info for each of the chapters. 


About Solidity

The solidity programming language is the language used to write smart contracts on the Ethereum blockchain. As of my initial writing of this chapter the current compiler version was 0.6.6. However, the versions change rapidly. For example, when I started coding in solidity 2 years ago, solidity was in version 4 and now its version 7 with major library and coding stylistic requirement updates in version 5. 

So, note that when compiling your code for labs its best to use the version sited in that particular example. This is easily achieved in the online compilers, by selecting the compiler version from the dropdown menu. If you would like to give yourself a small challenge, use the latest compiler version and try to modify the code to work with it. Usually this just requires a few minor modifications and can be a good learning experience under the hood of how Solidity works and what has changed.

Solidity is very similar to writing JavaScript and is fully object oriented. In the intro chapters we will attempt to provide a quick overview of solidity understanding needed for a penetration tester. This will not be full guide to programming, as programming is considered to be a pre-requisite to application hacking. Instead this chapter will be a gentle introduction of needed concepts you will use throughout this book. Solidity is also a needed pre-requisite for understanding the rest of the information and its associated exploitation course. 

However, as long as you understand general programming concepts then you should have no trouble understanding solidity. It is a relatively easy language to get up and running with quickly in comparison to more mature languages like C++ and Java which may take a more significant amount of time to learn.

The most important thing to understand with solidity is that unlike traditional languages, solidity handles transactions of monetary value by default. Meaning you don't need to attach to a payment API to add transactions to your applications. Payment functionality is baked into the language as its primary purpose and for usage with the Ethereum blockchain.  All that's needed for financial transactions in solidity is a standard library transfer function, and you can easily send value to anyone's public address. 

For example, the following simple function will transfer a specified amount of Ether to the user calling the function provided they have a large enough balance to allow the transfer. But lets not dive into that just yet. 

 

1.  function withdraw (uint amount) {
2.     require (amount <= balances[msg.sender]);
3.     msg.sender.transfer(amount);
4.  }

 

Structure of a Smart Contract

Rather than discuss payments at this point, let's not jump to far ahead of ourselves. We need to understand the structure of a smart contract. Let's take a look at a Hello World example. We will analyze all of the key aspects that make solidity different then other languages you may currently understand.

You can easily follow along with this on http://remix.ethereum.org which is a free online IDE and compiler for coding in solidity. A full video walk through of Remix is included later on in this chapter.  Remix contains in-browser compilers and virtual environments that emulate block creation and allow you to send and receive transactions.  This is a powerful development tool and absolutely free to use. 

Below is the simple code example we will analyze before moving on to a live walk through. 

1.  pragma solidity 0.6.6; 
2.   
3.  contract HelloWorld {
4.           
5.     constructor () public payable {
6.           //This is a comment
7.           //You can put your configuration information here
8.     }
9.   
10.   function hello () public pure returns (string memory) {
11.                  return "Hello World";
12.         }
13.}

 

There is a lot going on in this small program so I will try to break it down as simple as possible. In the first line, we have the pragma statement which is required at the top of each program to let the compiler know which version of solidity this code was written for.  As I said earlier, these versions change rapidly due to the evolving technology and many changes are implemented into each new version. So, the compiler needs to know which version you intended this to run on.

On line 3 is the word "contract" followed by whatever name you wish to call your contract. The contract's functionality is then enclosed in curly braces. This is similar to creating a class in any other language. It's a block of associated code that can be inherited, or interfaced with and contains its own variables and methods.

On line 5 contained within the contract curly braces we have a constructor denoted by the word "constructor".  The constructor is run one time at contract creation and used to setup any variables or details of the smart contract. This is often used for creating an administrator of the contract or other items that are needed prior to contract usage. 

Functions and variables within Solidity also have various types and visibility set with their creation.  In this case also on line 5 you will see the words "public" and "payable" used to describe the constructor. 

Public you may be familiar with as it's a common visibility keyword used in other languages denoting that anyone can call this function. There are other visibility types in Solidity listed below, we will cover each of these in more detail as we use them to our advantage when hacking smart contracts:

 

Public

This allows anyone to call and use this function

 

Private

This allows only the current contract and its functions to call it directly.

 

Internal

This is similar to private except it also allows derived contracts to use its functionality

 

External

External can only be called externally by other contracts unless the "this" keyword is used with the function call.

 

The second keyword in the constructor definition "payable" you may not be familiar with unless you have worked on blockchain projects. The word payable within solidity is needed on any item that can receive Ether. So, by setting the constructor as payable we can send a base amount of Ether to the contract when its deployed. This will add an initial monetary liquidity for whatever functionality the contract is providing. For example, if this were a gambling game, we would need some initial Ethereum to payout our winners before our revenues catch up with our payouts and we start collecting large sums of failed gambling revenue. 

Within the constructor is an example of how comments are handled in solidity, the simple double forward slash is used like in most languages. Comments function in the same way as any other language in that they are not processed and they are ignored by the compiler but are useful for understanding the code you wrote later after you have taking time apart from reading your code.

Finally, we have our simple hello function starting on line 10. Again, there is a lot going on here. First is the name of the function with parentheses that can contain arguments like in any other language. However, this function does not take arguments.

You will notice two more keywords in the function definition "pure" and "returns". Returns is simply the way the function denotes that it will return a value to the user, which it then states directly after it what type of variable it returns. In this case, it returns a string in memory.  We will talk about memory and storage later on and the security implications of them.

Next is the word "Pure" there are a couple types of functions in Solidity which will list below with a brief description.


View

This type of function does not modify or change the state of the contract but may return values and use global variables.

Pure

A pure function is a function which is completely self-contained in that it only uses local variables and it does not change the state of the smart contract.


Finally, in line 11 we return our string to the user who called the function. In the context of a user, this could be a physical user using an application or smart contract functionality or it could actually be another smart contract calling the function.

 

Hands on Lab – Remix HelloWorld

Now that we talked over in detail all the new concepts to solidity programs using a small example, lets compile and run this code on remix.ethereum.org.

Action Steps:

ü Browse to remix.etherum.org
ü Type out the the code from above (Do not copy Paste it)
ü Compile and deploy the code
ü Review the transaction in the log window

 

Intro to the Remix Development Environment Video


In Remix create a new file and type out the example helloworld code.  I would suggest that you actually type out all of the examples in this book. They will not be exhaustive or long and will provide you great value and make you comfortable when it comes to writing your own exploits and using the compilers and tools. These are all essential tools to your understanding.

Within your remix environment, you will want to select the compiler version 0.6.6 to ensure that this code runs correctly. If you typed out the code correctly you should not receive any errors and you will be able to deploy and interact with it. In the following video we will walk you through that process and explain some nuances of solidity. 


Explaining and Compiling HelloWorld Video: 






 

Lets now quickly review a few key points about the transaction that you saw within the video when compiling your code. This transaction is shown below. 

__________________________________________________________________________________

call to HelloWorld.hello

CALL

from      0xBF8B5A94eD4dFB45089b455B1A0e296D6669c625

 to           HelloWorld.hello() 0xADe285e11e0B9eE35167d1E25C3605Eba1778C86

 transaction cost               21863 gas (Cost only applies when called by a contract)

                                         execution cost 591 gas (Cost only applies when called by a contract)

 hash     0x14557f9552d454ca865deb422ebb50a853735b57efaebcfc9c9abe57ba1836ed

 input    0x19f...f1d21

 decoded input {}

 decoded output               {

                "0": "string: Hello World"

}

 logs       []

_________________________________________________________________________________

 

The output above is a hello transaction which contains the relevant data retrieved when you executed the hello function in the video. The first important thing to notice is the word "CALL". In solidity there are call and send transactions. The difference between the two is whether they change the state of the blockchain or not. In this case we did not change the state, we only retrieved information so a CALL was issued.  If we were changing variables and sending values then a SEND transaction would have been issued instead.

Next you will see the "From" address which should correspond with the address you used to call the transaction.  The "To" field should be the address the smart contract was given when you deployed the smart contract. You can view this on your deployment screen next to the deployed contract name by hitting the copy button and pasting it somewhere to see the full value.

You will then see the costs and gas associated with the transaction. Costs change based on the size of the contracts and the assembly code created by the compiler. Each instruction has a cost. We will cover that later when we do a bit of debugging and decompiling. 

Finally take note of the Decoded Output which contains the return string of "Hello World".

 

Summary

If you are new to solidity or new to programming in general this might have been a lot of information.  In the next chapter we cover a few more key solidity concepts before moving on to exploiting vulnerabilities where a much more in depth understanding of how solidity works and its security implications will be explored. For more solidity resources and full-length free tutorials check out the following references

  

Homework:

https://cryptozombies.io/en/course/

More info


FOOTPRITING AND INFORMATION GATHERING USED IN HACKING

WHAT IS FOOTPRITING AND INFORMATION GATHERING IN HACKING?

Footpriting is the technique used for gathering information about computer systems and the entities they belongs too. 
To get this information, a hacker might use various tools and technologies.

Basically it is the first step where hacker gather as much information as possible to find the way for cracking the whole system or target or atleast decide what types of attacks will be more suitable for the target.

Footpriting can be both passive and active.

Reviewing a company's website is an example of passive footprinting, 
whereas attempting to gain access to sensititve information through social engineering is an example of active information gathering.

During this phase hacking, a hacker can collect the following information>- Domain name
-IP Addresses
-Namespaces
-Employee information 
-Phone numbers
-E-mails 
Job information

Tip-You can use http://www.whois.com/ website to get detailed information about a domain name information including its owner,its registrar, date of registration, expiry, name servers owner's contact information etc.

Use of  Footprinting & Information Gathering in People Searching-
Now a days its very easy to find anyone with his/her full name in social media sites like Facebook, Instragram,Twitter,Linkdedin to gather information about date of birth,birthplace, real photos, education detail, hobbies, relationship status etc.

There are several sites like PIPL,PeekYou, Transport Sites such as mptransport,uptransport etc and Job placement Sites such as Shine.com,Naukari.com , Monster.com etc which are very useful for hacker to collect information about anyone.  
Hacker collect the information about you from your Resume which you uploaded on job placement site for seeking a job as well as  hacker collect the information from your vehicle number also from transport sites to know about the owner of vehicle, adderess etc then after they make plan how to attack on victim to earn money after know about him/her from collecting information.




INFORMATION GATHERING-It is the process of collecting the information from different places about any individual company,organization, server, ip address or person.
Most of the hacker spend his time in this process.

Information gathering plays a vital role for both investigating and attacking purposes.This is one of the best way to collect victim data and find the vulnerability and loopholes to get unauthorized modifications,deletion and unauthorized access.



More articles

  1. Hackrf Tools
  2. Hacking Tools Windows
  3. Hack Tool Apk
  4. Hacking Tools Name
  5. Hacking Tools
  6. Underground Hacker Sites
  7. Hacking Tools Free Download
  8. Hacker Techniques Tools And Incident Handling
  9. Best Pentesting Tools 2018
  10. Hacker Tools Hardware
  11. Tools Used For Hacking
  12. Pentest Tools For Android
  13. Hack Rom Tools
  14. Usb Pentest Tools
  15. Hacker Tools Linux
  16. Hacking Tools For Kali Linux
  17. Pentest Tools Subdomain
  18. Growth Hacker Tools
  19. Hacking Tools Software
  20. Pentest Tools Find Subdomains
  21. Hacking Tools 2020
  22. Game Hacking
  23. Hack Tools For Pc
  24. Hacking App
  25. Tools Used For Hacking
  26. Underground Hacker Sites
  27. Hacking Tools Kit
  28. Hack Tools Pc
  29. Hacking Tools For Kali Linux
  30. Pentest Box Tools Download
  31. Pentest Tools For Mac
  32. Hack Tools Online
  33. Hacker Security Tools
  34. Pentest Box Tools Download
  35. Pentest Tools Bluekeep
  36. Nsa Hacker Tools
  37. How To Hack
  38. Hack Tool Apk
  39. Hacking Tools For Pc
  40. Pentest Automation Tools
  41. Hack And Tools
  42. Hack Rom Tools
  43. Hacker Tools Hardware
  44. World No 1 Hacker Software
  45. Nsa Hack Tools
  46. Hack Tools Online
  47. Hack Tools Online
  48. Hacker Hardware Tools
  49. Pentest Tools Windows
  50. Hack Tools For Windows
  51. Hacker Tools Free
  52. Hacking Tools Kit
  53. Pentest Tools Bluekeep
  54. Free Pentest Tools For Windows
  55. What Are Hacking Tools
  56. Usb Pentest Tools
  57. Hacking Tools Windows
  58. Hack Tools Mac
  59. Kik Hack Tools
  60. Nsa Hack Tools
  61. Github Hacking Tools
  62. Hack Tools For Windows
  63. Pentest Tools Review
  64. How To Install Pentest Tools In Ubuntu
  65. Pentest Tools For Mac
  66. Hacking Tools And Software
  67. Pentest Tools Kali Linux
  68. Best Pentesting Tools 2018
  69. Hak5 Tools
  70. Hack And Tools
  71. Pentest Tools Tcp Port Scanner
  72. Pentest Tools Review
  73. Hacking Tools For Windows
  74. Hacking Tools For Mac
  75. Hack Website Online Tool
  76. Pentest Tools Nmap
  77. Pentest Tools Github
  78. Hacking Apps
  79. Pentest Tools Tcp Port Scanner
  80. How To Hack
  81. Pentest Tools Website Vulnerability
  82. Pentest Tools Apk
  83. Hack Tools For Pc
  84. Black Hat Hacker Tools
  85. Growth Hacker Tools
  86. Hack Tools For Mac
  87. Hack App
  88. Pentest Tools
  89. Pentest Automation Tools
  90. What Are Hacking Tools
  91. Pentest Tools Kali Linux
  92. Pentest Tools Website Vulnerability
  93. Pentest Tools For Android
  94. Pentest Tools Nmap
  95. Termux Hacking Tools 2019
  96. Hacker Tools 2020
  97. Hacking Tools Windows 10
  98. Nsa Hack Tools
  99. Hacking Tools Windows 10
  100. Hacker Tools List
  101. Hacking Tools 2020
  102. Hacking Tools Download
  103. Hacker Tools 2019
  104. Pentest Tools Online
  105. Pentest Tools Linux
  106. Hacking Tools Mac
  107. Hacking App
  108. Hacking Tools Download
  109. Hacking Tools For Windows 7
  110. Hacking Tools Mac
  111. Hack Tool Apk No Root
  112. Hack Tool Apk No Root
  113. Hacking Tools For Mac
  114. Tools 4 Hack
  115. Beginner Hacker Tools
  116. Hak5 Tools
  117. Tools Used For Hacking
  118. Hack Tools Github
  119. Hack Tools Mac
  120. Tools Used For Hacking
  121. Hacking Tools Kit
  122. Hacking Tools For Games
  123. Hacker Tools For Windows
  124. Hacker Tools Mac
  125. Growth Hacker Tools
  126. Wifi Hacker Tools For Windows
  127. Pentest Tools For Windows
  128. Nsa Hack Tools Download
  129. Black Hat Hacker Tools
  130. Hackers Toolbox
  131. Hack Tools Github
  132. Hacker Tools Apk Download
  133. Hack Tools 2019
  134. Pentest Tools Review
  135. Computer Hacker
  136. World No 1 Hacker Software
  137. Hacking Tools Windows
  138. Tools For Hacker
  139. Pentest Tools Linux
  140. Pentest Tools Online
  141. Pentest Tools Tcp Port Scanner
  142. Pentest Tools Online
  143. Wifi Hacker Tools For Windows
  144. Pentest Reporting Tools
  145. Wifi Hacker Tools For Windows
  146. New Hack Tools
  147. Hacker Tools Linux
  148. Usb Pentest Tools
  149. Hack Tools For Ubuntu
  150. Pentest Tools List
  151. Pentest Box Tools Download
  152. Pentest Tools Android
  153. Hack Tools
  154. Pentest Tools Nmap
  155. Termux Hacking Tools 2019
  156. Hack Tool Apk
  157. Pentest Box Tools Download
  158. Hackrf Tools
  159. Pentest Tools Free
  160. Hacking Tools Free Download
  161. Hacker Tools Free
  162. Hacker Tools For Mac
  163. Ethical Hacker Tools
  164. Tools For Hacker
  165. Hacking Tools Software
  166. Pentest Tools For Windows
  167. Nsa Hack Tools Download
  168. Hack Website Online Tool
  169. Hacking Tools Name
  170. Top Pentest Tools
  171. Black Hat Hacker Tools
  172. Hacking Tools Windows
  173. New Hacker Tools
  174. Hacking Tools 2020
  175. Hacker Tools Linux
  176. Hacker Hardware Tools
  177. Pentest Tools Apk

S2 Dynamic Tracer And Decompiler For Gdb

Decompiling is very useful for understanding srtipped binaries, most dissasemblers like IDA or Hopper have a plugin for decompiling binaries, generating a c like pseudocode.

Static analysis, is very useful in most of cases, specially when the binary is not so big, or when you just have an address where to start to analyze. But some algorithms will be learned in less time by dynamic analysis like tracing or debugging.

In cookiemonsters team, we are working on several tracers with different focus, but all of them mix the concept of tracing and decompiling to generate human-readable traces.

S2 is my tracer & decompiler plugin for gdb, very useful for ctfs.
Some of the features are:

- signed/unsigned detecion
- conditional pseudocode (if)
- syscall resolution
- unroll bucles
- used registers values
- mem states
- strings
- logging



More information


  1. Hacking Tools For Windows
  2. New Hack Tools
  3. Hacker Tools Online
  4. How To Make Hacking Tools
  5. Hacker Tools Github
  6. Hacking Tools
  7. Hacking Tools For Windows Free Download
  8. Usb Pentest Tools
  9. Top Pentest Tools
  10. New Hack Tools
  11. Blackhat Hacker Tools
  12. Hack Tools For Ubuntu
  13. Hacking Tools
  14. Computer Hacker
  15. Hackrf Tools
  16. Best Pentesting Tools 2018
  17. Pentest Tools Windows
  18. Termux Hacking Tools 2019
  19. Pentest Tools Review
  20. Underground Hacker Sites
  21. Pentest Tools Online
  22. Black Hat Hacker Tools
  23. Pentest Tools Github
  24. Hack Website Online Tool
  25. Hacker Tools Free
  26. Pentest Tools Port Scanner
  27. Hacker Tools Apk
  28. Hacking Tools Software
  29. Black Hat Hacker Tools
  30. Pentest Tools Port Scanner
  31. Pentest Tools For Mac
  32. Pentest Tools Website
  33. Hacker Tools Apk Download
  34. Hackers Toolbox
  35. Hack Website Online Tool
  36. Hacking Tools Online
  37. Hack Tools For Pc
  38. Hacking Tools Usb
  39. Blackhat Hacker Tools
  40. Pentest Tools Website Vulnerability
  41. Pentest Tools Linux
  42. Hack Tools 2019
  43. Hacker Tools For Pc
  44. Hacker Tools Linux
  45. Hack Tools
  46. Hack Website Online Tool
  47. Hack Tools Download
  48. Android Hack Tools Github
  49. What Is Hacking Tools
  50. Hacking Tools
  51. Tools 4 Hack
  52. Hacking Tools And Software
  53. Github Hacking Tools
  54. Hackrf Tools
  55. Hacker Tools Free Download
  56. Hacker
  57. Kik Hack Tools
  58. Pentest Tools Kali Linux
  59. Best Pentesting Tools 2018
  60. Hack Tools Mac
  61. Hackrf Tools
  62. Easy Hack Tools
  63. Pentest Tools Apk
  64. Pentest Tools Open Source
  65. Best Pentesting Tools 2018
  66. Pentest Tools Online
  67. Hacking Tools For Pc
  68. Hack Tools Online
  69. Pentest Tools Tcp Port Scanner
  70. Blackhat Hacker Tools
  71. How To Hack
  72. Hacker Tools For Ios
  73. Hack Tools For Windows
  74. Hacker Tools For Mac
  75. Hack App
  76. Bluetooth Hacking Tools Kali
  77. Hacking Tools For Kali Linux
  78. Hacker Tools For Mac
  79. Hacker Tools Mac
  80. Pentest Tools Open Source
  81. Hacker Tools Apk
  82. Hacker Tools Github
  83. Hacker Tools Mac
  84. Pentest Box Tools Download
  85. Pentest Tools Framework
  86. Free Pentest Tools For Windows
  87. Hack Tools 2019
  88. Hacking Tools Windows
  89. Hack Tools Github
  90. Hacking Tools Usb
  91. Best Hacking Tools 2019
  92. Pentest Tools Url Fuzzer
  93. Hacking Tools For Windows
  94. Hack Tools
  95. Hacking Tools For Windows 7
  96. New Hacker Tools
  97. Hack Tools
  98. Termux Hacking Tools 2019
  99. Hacker Tools 2019
  100. Hacking Tools Free Download
  101. Black Hat Hacker Tools
  102. Pentest Tools Website Vulnerability
  103. Pentest Automation Tools
  104. Pentest Tools For Mac
  105. Pentest Tools Github
  106. Hacking Apps
  107. Pentest Tools Online
  108. Hack Tools For Ubuntu
  109. Hack Tools For Mac
  110. Hack Tools Mac
  111. Hacking Tools For Games
  112. Hack Tools
  113. Pentest Tools Online
  114. Hacker Tools Online
  115. Hacking Tools
  116. Hacker Tools Software
  117. Pentest Tools For Ubuntu
  118. Hacking Tools Free Download
  119. Hacker Tools Github
  120. Hacker Tools Apk
  121. Hacker Tools For Ios
  122. Hack And Tools
  123. Hacker Tools Hardware
  124. Hacking Apps
  125. How To Hack
  126. Hack Apps
  127. Hacking Tools And Software
  128. Hacking App
  129. Hackers Toolbox
  130. Hacker Tools 2020
  131. Hacking Tools Software
  132. New Hack Tools
  133. Hack And Tools
  134. Pentest Tools Nmap

jueves, 18 de enero de 2024

OSWA™


"The OSWA™-Assistant is a self-contained, no Operating System required, freely downloadable, standalone toolkit which is solely focused on wireless auditing. As a result, in addition to the usual WiFi (802.11) auditing tools, it also covers Bluetooth and RFID auditing. Using the toolkit is as easy as popping it into your computer's CDROM and making your computer boot from it!" read more...

Website: http://oswa-assistant.securitystartshere.org

More information