pragma solidity ^0.8.20;
contract ContractCall {
address public owner;
uint256 public num;
address public lib;
constructor() {
owner = msg.sender;
}
function setLibAddress(address _Lib) public {
lib = _Lib;
}
function nowOwner() public view returns (address) {
return owner;
}
function callDelegate(uint256 _num) public payable returns (bool)
{
(bool success, ) = lib.delegatecall(abi.encodeWithSignature("changeOwner(uint256)", _num));
return success;
}
}
pragma solidity ^0.8.20;
contract ChangeOwner {
address public owner;
uint256 public num;
function changeOwner(uint256 _num) public {
owner = msg.sender;
num = _num;
}
}
각각 deploy 후 setLibAddress에 ChangeOwner 컨트랙트의 주소를 넣고 callDelegate를 호출하면 num 및 owner가 변경된다.
주의할 점은 변수의 순서가 일치하여야 한다.
만약 아래와 같이 코딩했다면, ContractCall의 owner에는 num, num에는 owner가 저장된다.
contract ContractCall {
address public owner;
uint256 public num;
address public lib;
contract ChangeOwner {
uint256 public num;
address public owner;
root@DESKTOP-3NGJPPV:/home/server/kiloton-main# sudo systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
int x = 1;
if (x + x == 3)
{
// 불투명 술어 거짓. 실행되면 안되므로 더미 코드가 들어감
}
if (x - 1 == 0)
{
// 불투명 술어 참. 실행되어야 하는 코드
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
srand(time(NULL));
int i = rand() % 3;
if (i == 0)
{
printf("0\n");
}
else if (i == 1)
{
printf("1\n");
}
else if (i == 2)
{
printf("2\n");
}
else if (i == 3)
{
printf("3\n");
}
return i;
}
IDA Result (Original)
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // w0
int v5; // [xsp+8h] [xbp-8h]
v3 = time(0LL);
srand(v3);
v5 = rand() % 3;
if ( v5 )
{
switch ( v5 )
{
case 1:
printf("1\n");
break;
case 2:
printf("2\n");
break;
case 3:
printf("3\n");
break;
}
}
else
{
printf("0\n");
}
return v5;
}
IDA Result (Obfuscation)
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // w0
int v4; // w19
v3 = time(0LL);
srand(v3);
v4 = rand() % 3;
switch ( v4 )
{
case 2:
puts("2");
break;
case 1:
if ( ((x + x * x) & 1) != 0 && y > 9 )
goto LABEL_16;
while ( 1 )
{
puts("1");
if ( ((x + x * x) & 1) == 0 || y < 10 )
break;
LABEL_16:
puts("1");
}
break;
case 0:
if ( ((x + x * x) & 1) != 0 && y > 9 )
goto LABEL_13;
while ( 1 )
{
puts("0");
if ( ((x + x * x) & 1) == 0 || y < 10 )
break;
LABEL_13:
puts("0");
}
break;
}
return v4;
}