Skip to content

Commit

Permalink
setup travisci, add c++ header and example
Browse files Browse the repository at this point in the history
  • Loading branch information
zTrix committed Aug 5, 2015
1 parent 2b0295f commit 5388e4e
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 12 deletions.
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
sudo: required

language: cpp

os: linux

install:
- sudo pip install protobuf
- wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
- tar -xzvf protobuf-2.6.1.tar.gz
- cd protobuf-2.6.1 && ./configure --prefix=/usr && make && sudo make install && cd ..

script:
- ./travis.sh $CONFIG

env:
- CONFIG=cpp
- CONFIG=python

notifications:
email: true
File renamed without changes.
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
CXX := $(shell command -v clang++ || command -v g++)
CXXFLAGS := -O2
LDFLAGS += -L./ -lsqlchop `pkg-config --libs protobuf`

.PHONY: all clean

all:
protoc --python_out=. preprocessio.proto
echo 'Done!'
all: sqlchop_cpp sqlchop_python

sqlchop_cpp: sqlchop_test
sqlchop_python: sqlchopio_pb2.py

sqlchopio_pb2.py:
protoc --python_out=. sqlchopio.proto

sqlchopio.pb.cc:
protoc --cpp_out=. sqlchopio.proto

sqlchop_test: sqlchopio.pb.cc
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ test.cc sqlchopio.pb.cc

clean:
rm -f sqlchop_test
rm -f sqlchop.pyc
rm -f preprocessio_pb2.py{,c}
rm -f sqlchopio_pb2.py{,c}
rm -f sqlchopio.pb.{cc,h,o}
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

# SQLChop

A novol SQL injection detection engine.
[![Build Status](https://travis-ci.org/chaitin/sqlchop.svg?branch=master)](https://travis-ci.org/chaitin/sqlchop)

A novel SQL injection detection engine.

SQLChop is a demo tool of Blackhat 2015 arsenal session. https://www.blackhat.com/us-15/arsenal.html#yusen-chen

Expand All @@ -23,17 +25,23 @@ http://sqlchop.chaitin.com/doc.html

## Dependencies

The current alpha testing release is provided as a python library. C++ headers and examples will be released soon.
The SQLChop alpha testing release includes the c++ header and shared object, a python library, and also some sample usages. The release has been tested on most linux distributions.

To install `protobuf-python`, you can use `pip`, `easy_install` or `pacman`, `yum`, `apt-get` as needed.
If using python, you need to install `protobuf-python`, e.g.:

```
$ sudo pip install protobuf
```

If using c++, you need to install `protobuf`, `protobuf-compiler` and `protobuf-devel`, e.g.:

```
$ sudo yum install protobuf protobuf-compiler protobuf-devel
```

## Build

- Download latest release at https://github.com/chaitin/sqlchop/releases
- make
- run test.py
- Make
- Run `python2 test.py` or `LD_LIBRARY_PATH=./ ./sqlchop_test`
- Enjoy!
File renamed without changes.
42 changes: 42 additions & 0 deletions sqlchop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2015 Chaitin Tech.
*
* Licensed under:
* https://github.com/chaitin/sqlchop/blob/master/LICENSE
*
*/

#ifndef __SQLCHOP_SQLCHOP_H__
#define __SQLCHOP_SQLCHOP_H__

#define SQLCHOP_API __attribute__((visibility("default")))

#ifdef __cplusplus
extern "C" {
#endif

struct sqlchop_object_t;

enum {
SQLCHOP_RET_SQLI = 1,
SQLCHOP_RET_NORMAL = 0,
SQLCHOP_ERR_SERIALIZE = -1,
SQLCHOP_ERR_LENGTH = -2,
};

SQLCHOP_API int sqlchop_init(const char config[],
struct sqlchop_object_t **obj);
SQLCHOP_API float sqlchop_score_sqli(const struct sqlchop_object_t *obj,
const char buf[], size_t len);
SQLCHOP_API int sqlchop_classify_request(const struct sqlchop_object_t *obj,
const char request[], size_t rlen,
char *payloads, size_t maxplen,
size_t *plen, int detail);

SQLCHOP_API int sqlchop_release(struct sqlchop_object_t *obj);

#ifdef __cplusplus
}
#endif

#endif // __SQLCHOP_SQLCHOP_H__
12 changes: 9 additions & 3 deletions sqlchop.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/usr/bin/env python2
#
# Copyright (C) 2015 Chaitin Tech.
#
# Licensed under:
# https://github.com/chaitin/sqlchop/blob/master/LICENSE
#

import os, sys
from ctypes import *
try:
from preprocessio_pb2 import Request, Payload, ListOfPayload
from sqlchopio_pb2 import Request, Payload, ListOfPayload
except ImportError:
print 'ImportError: failed to import preprocessio_pb2'
print 'Please install protobuf-python first and then execute make to generate preprocessio_pb2.py'
print 'ImportError: failed to import sqlchopio_pb2'
print 'Please install protobuf-python first and then execute make to generate sqlchopio_pb2.py'
sys.exit(10)

_cwd = os.path.dirname(os.path.realpath(__file__))
Expand Down
File renamed without changes.
67 changes: 67 additions & 0 deletions test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2015 Chaitin Tech.
*
* Licensed under:
* https://github.com/chaitin/sqlchop/blob/master/LICENSE
*
* Sample usage:
* $ LD_LIBRARY_PATH=./ ./test
*
*/


#include <string>
#include <iostream>

#include "sqlchop.h"
#include "sqlchopio.pb.h"

#define MAXLEN 1 << 20

using namespace std;

sqlchop_object_t *pdetector;
string str_in;
char out[MAXLEN];

Request req;
ListOfPayload list_of_payload;

int main() {

req.set_urlpath("/chaitin/"
"sqlchop?="
"c2VsZWN0JTIwc3FsY2hvcCUyMGZyb20lMjBjaGFpdGluJTIwd2hlcmUlMjBo"
"ZWxsbyUyMCUzRCUyMHdvcmxkJTIwJTI2JTI2JTIwJTI3aG9wZSUyNyUyMCUy"
"N3lvdSUyNyUyMGxpa2UlMjBpdAo=");
req.SerializeToString(&str_in);

size_t out_len;
sqlchop_init(0, &pdetector);
sqlchop_classify_request(pdetector, str_in.c_str(), str_in.length(), out,
MAXLEN, &out_len, 1);

list_of_payload.ParseFromString(string(out, out_len));

for (int pi = 0; pi < list_of_payload.payloads_size(); pi++) {
cout << "Payload #" << pi << ":" << endl;
const Payload& payload = list_of_payload.payloads(pi);
cout << "Value:" << endl;
cout << payload.value() << endl;
if (payload.has_key()) {
cout << "Key:" << endl;
cout << payload.key() << endl;
}
if (payload.has_source()) {
cout << "Source:" << endl;
cout << payload.source() << endl;
}
if (payload.has_score()) {
cout << "Score:" << endl;
cout << payload.score() << endl;
}
cout << endl;
}

return 0;
}
6 changes: 6 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/usr/bin/env python2
#
# Copyright (C) 2015 Chaitin Tech
#
# Licensed under:
# https://github.com/chaitin/sqlchop/blob/master/LICENSE
#

import pprint
from sqlchop import *
Expand Down
21 changes: 21 additions & 0 deletions travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

test_cpp() {
LD_LIBRARY_PATH=./ ./sqlchop_test
}

test_python() {
python test.py
}

# -------- main --------

if [ "$#" -ne 1 ]; then
echo "Usage: $0 { cpp | python }"
exit 1
fi

set -e # exit immediately on error
set -x # display all commands
make sqlchop_$1
eval "test_$1"

0 comments on commit 5388e4e

Please sign in to comment.