segunda-feira, 31 de agosto de 2020

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/

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

    domingo, 30 de agosto de 2020

    What Is A Vpn And How Is It Works ?

    What Is A VPN?

    VPN stands for Virtual Private Network, and maybe you have heard or read that term in association with privacy and geolocation. In this article we will learn and look into what exactly is it how does it work and what can it do for you.

    How Does A VPN Work?

    Let me explain it now but before we dive into VPNs, let me tell you a little bit about how the internet works now. At home, you have probably got some router or modem from your telephone company or your internet service provider. Then that is connected to your desktop, maybe by an Ethernet cable, to your smartphone over Wi-Fi, perhaps to your laptop over Wi-Fi and so on.

    Inside your house when you do a laptop talk or your PC talk or your phone talk that is part of your private network, and that does not go out onto the internet. It stays inside your house, but the moment you open a web page somewhere out on the internet that data flows through your modem down into your local phone company or ISP and then out across the internet.

    It will travel across the internet until it gets to the server the server will then reply with some information that will come back through the internet into your local telecommunications provider or ISP down through to your modem and then back onto your PC or your Android smartphone.

    Now, while all that data is rushing around the internet, it needs to know where it is going and the things to know where they are going. They need an address it is the same with the postal service is the same when you want to go and visit somebody. It is the same with data on the internet.

    There are different layers of addressing or different types of addressing that go on, but at the highest level, each of these packets of information has what is called an IP address. The IP address is you have probably seen them there those four digits from 0 to 255 with dots in between them so maybe like 178.304.67.

    The modem or your router has probably been assigned an IP address from your ISP and what happens in is that when your data goes through the internet every piece of equipment, it touches every router every server it touches knows that your IP address. It is done that is not because they are trying to spy on you but because trying to connect collect data about the number of people that clicked into their website.

    What a VPN does is it allows you to create a tunnel a connection from your home computer to a server somewhere else in the world. The connection is encrypted, and then when I access something on the Internet, it goes through that tunnel and then it arrived at that other server and then it goes on to the Internet, and it will finally arrive at the web server or the service. Your IP address will no longer be your IP address. The IP address of the VPN server protects your IP.

    If you use a VPN, first of all, your local telecommunications provider and your local government have no idea about the sites that you are accessing. When you go through the VPN, it is all encrypted. VPN allows you to connect to another server in another country.


    @£√£RYTHING NT

    Continue reading

    1. Hack Tools For Ubuntu
    2. Hack Website Online Tool
    3. Hacker Tools For Mac
    4. Hacking Tools For Windows
    5. Physical Pentest Tools
    6. Hack App
    7. Hacking Tools Github
    8. Tools For Hacker
    9. Kik Hack Tools
    10. Hack Tools
    11. Hacking Tools Name
    12. Pentest Tools Find Subdomains
    13. Tools 4 Hack
    14. Hacker Search Tools
    15. Pentest Tools Free
    16. Game Hacking
    17. Pentest Tools Download
    18. Pentest Tools Framework
    19. Pentest Tools Tcp Port Scanner
    20. Pentest Tools Framework
    21. How To Hack
    22. Nsa Hacker Tools
    23. Pentest Tools Github
    24. Github Hacking Tools
    25. Nsa Hacker Tools
    26. Hacking Tools For Windows 7
    27. Hack Website Online Tool
    28. Best Hacking Tools 2019
    29. Hack Tools Github
    30. Hacking Tools Usb
    31. Hacking Tools Usb
    32. Hacking Tools For Games
    33. Hacker Tools Windows
    34. Hack Tools Online
    35. Hacking Tools Free Download
    36. Hack Tools Pc
    37. How To Install Pentest Tools In Ubuntu
    38. Hacking Tools 2020
    39. Hacker
    40. Hacker Tools For Pc
    41. Hackers Toolbox
    42. Black Hat Hacker Tools
    43. Hacker Tools Github
    44. How To Install Pentest Tools In Ubuntu
    45. Hacker Tools Apk
    46. Free Pentest Tools For Windows
    47. Hackrf Tools
    48. Hacking Tools Usb
    49. Physical Pentest Tools
    50. How To Hack
    51. Hacking Tools Mac
    52. Hacking Tools For Beginners
    53. Pentest Tools For Android
    54. Hacker Tools Windows
    55. Hacking Tools For Games
    56. Wifi Hacker Tools For Windows
    57. Wifi Hacker Tools For Windows
    58. Growth Hacker Tools
    59. Hacking Tools Name
    60. Hacking Tools Pc
    61. Pentest Tools Github
    62. Pentest Tools Nmap
    63. Hacking Tools For Beginners
    64. Tools Used For Hacking
    65. Pentest Tools Android
    66. Hacker Tool Kit
    67. Hacker Tools Hardware

    AutoNSE - Massive NSE (Nmap Scripting Engine) AutoSploit And AutoScanner


    Massive NSE (Nmap Scripting Engine) AutoSploit and AutoScanner. The Nmap Scripting Engine (NSE) is one of Nmap's most powerful and flexible features. It allows users to write (and share) simple scripts (using the Lua programming language ) to automate a wide variety of networking tasks. Those scripts are executed in parallel with the speed and efficiency you expect from Nmap. Users can rely on the growing and diverse set of scripts distributed with Nmap, or write their own to meet custom needs. For more informations https://nmap.org/book/man-nse.html

    Installation
    $ git clone https://github.com/m4ll0k/AutoNSE.git
    $ cd AutoNSE
    $ bash autonse.sh

    Exmaples
    $ bash autonse.sh




    More information

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