Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit a3934c1

Browse files
author
steinkirch
committed
first:
0 parents  commit a3934c1

File tree

307 files changed

+555193
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

307 files changed

+555193
-0
lines changed

Gemfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
source "http://rubygems.org"
2+
3+
gem 'nyan-cat-formatter'
4+
gem 'ruby-debug19'
5+
gem 'rspec'
6+
gem 'rdoc'
7+
gem 'activerecord'
8+
gem 'colorize'
9+
gem 'rubyless'

Gemfile.lock

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
activemodel (3.1.3)
5+
activesupport (= 3.1.3)
6+
builder (~> 3.0.0)
7+
i18n (~> 0.6)
8+
activerecord (3.1.3)
9+
activemodel (= 3.1.3)
10+
activesupport (= 3.1.3)
11+
arel (~> 2.2.1)
12+
tzinfo (~> 0.3.29)
13+
activesupport (3.1.3)
14+
multi_json (~> 1.0)
15+
archive-tar-minitar (0.5.2)
16+
arel (2.2.1)
17+
builder (3.0.0)
18+
colorize (0.5.8)
19+
columnize (0.3.6)
20+
diff-lcs (1.1.3)
21+
i18n (0.6.0)
22+
json (1.6.4)
23+
linecache19 (0.5.12)
24+
ruby_core_source (>= 0.1.4)
25+
multi_json (1.0.4)
26+
nyan-cat-formatter (0.0.5)
27+
rdoc (3.12)
28+
json (~> 1.4)
29+
rspec (2.7.0)
30+
rspec-core (~> 2.7.0)
31+
rspec-expectations (~> 2.7.0)
32+
rspec-mocks (~> 2.7.0)
33+
rspec-core (2.7.1)
34+
rspec-expectations (2.7.0)
35+
diff-lcs (~> 1.1.2)
36+
rspec-mocks (2.7.0)
37+
ruby-debug-base19 (0.11.25)
38+
columnize (>= 0.3.1)
39+
linecache19 (>= 0.5.11)
40+
ruby_core_source (>= 0.1.4)
41+
ruby-debug19 (0.11.6)
42+
columnize (>= 0.3.1)
43+
linecache19 (>= 0.5.11)
44+
ruby-debug-base19 (>= 0.11.19)
45+
ruby_core_source (0.1.5)
46+
archive-tar-minitar (>= 0.5.2)
47+
ruby_parser (2.3.1)
48+
sexp_processor (~> 3.0)
49+
rubyless (0.8.6)
50+
ruby_parser (>= 2.0.4)
51+
sexp_processor (>= 3.0.1)
52+
sexp_processor (3.0.10)
53+
tzinfo (0.3.31)
54+
55+
PLATFORMS
56+
ruby
57+
58+
DEPENDENCIES
59+
activerecord
60+
colorize
61+
nyan-cat-formatter
62+
rdoc
63+
rspec
64+
ruby-debug19
65+
rubyless

README.rdoc

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
===========================================================
2+
= Monitoring Cross-site Request Forgery Attacks (MonCSRF)
3+
Stony Brook University, January/2012.
4+
===========================================================
5+
6+
7+
== Introduction
8+
9+
10+
MonCSRF is designed to detect requests in a web server that may result on Cross-site Request Forgery (CSRF) attacks [1] [2] [3] [4] [5].
11+
12+
MonCSRF parses a given log file derived from a web server with DIVA [6] and verifies whether (and how) the requests in this file had the state of the system changed (named potential unsafe requests).
13+
14+
15+
MonCSRF is written in Ruby 1.9.2 and Ragel [7][8].
16+
17+
18+
19+
== Strategies
20+
21+
22+
23+
MonCSRF contains two different strategies for parsing a log file from DIVA.
24+
25+
26+
=== Parsing by Regular Expressions (REGEXP)
27+
28+
29+
The class representing this strategy is located at:
30+
31+
/lib/log_parser/strategies/sql/regexp.rb
32+
33+
34+
The default running does not use this strategy.
35+
36+
37+
=== Parsing into an Abstract Syntact Tree (AST)
38+
39+
The class representing this strategy is located at:
40+
41+
/lib/log_parser/strategies/sql/ragel.rl
42+
43+
44+
One can generates the .rb file by:
45+
46+
$ ragel -R ragel.rl
47+
48+
Ragel is a state machine compiler and parse generator. It combines lex and yacc into one and build a full state-machine for the input stream, i.e., one state-machine for the parser and lexer [10] [11].
49+
50+
The machine of states parse the SQL request. In an inital state, it receives a string. If in the of the string, the machine is in a final state, the SQL is valid. The AST is a way th machine use to save the data.
51+
The machine can get four initial paths: UPDATE, DELETE, SELECT, INSERT. It saves into the AST when executes the parse. Ragel has builting Graphviz [12] support to create state charts:
52+
$ ragel -R ragel.rl | rlgen-dot > ragel.dot
53+
54+
== Whitelisting
55+
56+
Every time one runs MonCSRF, every the potential unsafe requests will be compared to a whitelist. In the case which the program finds a previous similar whitelisted request (i.e., with same syntactic structure), the new request is automatically marked as safe. If the new request is not in the whitelist, the program will generate an alert and ask about the safety of it.
57+
58+
59+
The whitelist file can be inspected at:
60+
61+
62+
/white_list
63+
64+
65+
66+
== Tree Struture of the Files
67+
68+
├── bin
69+
70+
│   └── parser.rb
71+
72+
├── lib
73+
74+
│   ├── log_parser
75+
76+
│   │   ├── log_entry.rb
77+
78+
│   │   ├── log.rb
79+
80+
│   │   ├── sql_info.rb
81+
82+
│   │   ├── strategies
83+
84+
│   │   │   └── sql
85+
86+
│   │   │   ├── base.rb
87+
88+
│   │   │   ├── ragel.dot
89+
90+
│   │   │   ├── ragel.rb
91+
92+
│   │   │   ├── ragel.rl
93+
94+
│   │   │   ├── README_strategies
95+
96+
│   │   │   └── regexp.rb
97+
98+
│   │   └── white_list.rb
99+
100+
│   ├── log_parser.rb
101+
102+
│   └── runtime.rb
103+
104+
105+
106+
== Testings (For Developers)
107+
108+
MonCSRF was written using testings:
109+
110+
$ gem install bundler
111+
112+
$ bundle
113+
114+
$ rspec spec
115+
116+
117+
├── spec
118+
119+
│   ├── fixtures
120+
121+
│   │   ├── log
122+
123+
│   │   ├── white_list
124+
125+
│   ├── integration
126+
127+
│   │   └── runtime_spec.rb
128+
129+
│   ├── spec_helper.rb
130+
131+
│   ├── strategies
132+
133+
│   │   └── sql
134+
135+
│   │   ├── ragel_spec.rb
136+
137+
│   │   └── regext_spec.rb
138+
139+
│   ├── support
140+
141+
│   │   └── shared_example_strategy_sql.rb
142+
143+
│   └── unit
144+
145+
│   ├── log_entry_spec.rb
146+
147+
│   ├── log_spec.rb
148+
149+
│   ├── sql_info.rb
150+
151+
│   └── white_list_spec.rb
152+
153+
154+
155+
156+
== Running MonCSRF
157+
158+
To run MonCSRF, one needs to give the name of the log file:
159+
160+
$ bin/parser.rb PATH_TO_THE_LOG
161+
162+
163+
To run monCSRF using the default logs/log file:
164+
165+
$./run.sh
166+
167+
To test benchmark:
168+
169+
$./benchmark.sh
170+
171+
172+
173+
== Documentation
174+
The complete documentation of monCSRF in HTML is at:
175+
176+
/doc/README_rdoc.html
177+
178+
179+
This documentation was generated using RDoc[9] and can be updated by:
180+
181+
$ bundle
182+
183+
$ rdoc
184+
185+
186+
187+
=== Developers
188+
189+
Marina von Steinkirch, steinkirch at gmail.com
190+
191+
Riccardo Pelizzi, r.pelizzi at gmail.com
192+
193+
194+
195+
=== References
196+
[1] CWE/SANS Top 25 Most Dangerous Software Errors, http://cwe.mitre.org/top25/index.html.
197+
[2] Jovanovic, N., Kirda, E., & Kruegel, C., Preventing cross site request forgery attacks, 2007.
198+
[3] Barth, A., Jackson, C., & Mitchell, J.C., Robust Defenses for Cross-Site Request Forgery, CCS 2008.
199+
[4] R. Pelizzi & R. Sekar, A Server- and Browser- Transparent CSRF Defense for Web 2.0., 2011.
200+
[5] Xu, W., Bhatkar, E. & Sekar, R., Taint-enhanced policy enforcement, 2006.
201+
[6] R. Sekar, An Efficient Black-Box Technique for Defeating Web Application Attacks, 2008.
202+
[7] RVM Sources, http://beginrescueend.com/.
203+
[8] Ragel Sources, http://www.complang.org/ragel.
204+
[9] RDoc Sources, http://rdoc.sourceforge.net/.
205+
[10] http://jan.kneschke.de/projects/mysql/sql-parser-in-rage-l.
206+
[11] http://www.devchix.com/2008/01/13/a-hello-world-for-ruby-on-ragel-60/.
207+
[12] http://www.graphviz.org/.

benchmark.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
if [ $1 ]
4+
then
5+
LINES=$(wc -l $1)
6+
echo "LINES: $LINES"
7+
time ./bin/parser.rb $1 -b
8+
else
9+
echo "Log File not found or not specified."
10+
fi

bin/parser.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env ruby
2+
3+
require File.expand_path('lib/log_parser')
4+
5+
# This is the main file that will run the parser on a log file of our choice..
6+
# Usage: we can either run it or calculate benchmark. For this second option the argument is -b.
7+
# The name of the log is the first argument.
8+
# It calls the class lib/runtime.rb.
9+
10+
benchmark = false
11+
benchmark = true if ARGV[1] == '-b'
12+
Runtime.run(ARGV[0], benchmark)

0 commit comments

Comments
 (0)