Skip to content

Commit 38ff443

Browse files
scripts for console json Structure-Aware-Fuzzing demonstration
1 parent e3435de commit 38ff443

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed

console_demo/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
BLOBSTAMPER_SRC := $(wildcard ../blobstamper/*.cpp)
3+
BLOBSTAMPER_OBJ := $(addsuffix .o, $(basename $(BLOBSTAMPER_SRC)))
4+
5+
EXAMPLES_SRC = $(wildcard *.cpp)
6+
EXAMPLES_BIN = $(basename $(EXAMPLES_SRC))
7+
8+
9+
all: $(EXAMPLES_BIN)
10+
11+
build-libtappp:
12+
$(MAKE) -C ../libtappp
13+
14+
%: %.cpp $(BLOBSTAMPER_OBJ) $(BLOBSTAMPER_PG_OBJ) $(WRAPPERS_OBJ)
15+
$(CXX) $(CXXFLAGS) -I.. -o $@ $< $(BLOBSTAMPER_OBJ)
16+
17+
clean:
18+
-rm $(EXAMPLES_BIN) 2>/dev/null
19+
20+
.PHONY: test clean all
21+

console_demo/_run.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
PLAY_TIME="1m 2s"
4+
SAMPLE_SIZE=256
5+
6+
dd if=/dev/random of=buf count=1 bs=$SAMPLE_SIZE
7+
8+
9+
tmux split-window -v "watch -d -n0.1 -c './pulp2json buf| jq -C'";
10+
tmux split-window -h "watch -d -n0.1 -c 'hexdump buf'"
11+
12+
tmux new-window -P -d -n pseudo-fuzz "watch -d -n0.1 './pseudo_fuzz.pl'"
13+
tmux new-window -P -d -n watchdog "sleep $PLAY_TIME; tmux kill-session"
14+
15+

console_demo/pseudo_fuzz.pl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use Path::Tiny;
5+
use bytes;
6+
7+
die "file 'buf' not found" unless -e "buf";
8+
9+
my $size = -s "buf";
10+
11+
my $offset = int(rand($size));
12+
my $value = int(rand(256));
13+
14+
open(my $out, '+<:raw', 'buf');
15+
seek($out, $offset, 0);
16+
print $out pack('C', $value);
17+
18+
close $out;
19+

console_demo/pulp2json.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/******************************************************************************
2+
*
3+
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
******************************************************************************/
18+
19+
#include <string>
20+
#include <vector>
21+
#include <iostream>
22+
23+
#include "blobstamper/stamp_json.h"
24+
#include <sys/stat.h>
25+
26+
#include <fstream>
27+
28+
29+
long GetFileSize(std::string filename)
30+
{
31+
struct stat stat_buf;
32+
int rc = stat(filename.c_str(), &stat_buf);
33+
return rc == 0 ? stat_buf.st_size : -1;
34+
}
35+
36+
int
37+
main(int argc, char *argv[])
38+
{
39+
if (argc<2)
40+
{
41+
fprintf(stderr, "Please specify input file name as first argument\n");
42+
exit(1);
43+
}
44+
std::string file_name = argv[1];
45+
46+
std::fstream f{file_name};
47+
if (!f)
48+
{
49+
std::cerr << "Unable to open file '"<<file_name<<"'\n";
50+
exit (1);
51+
}
52+
long file_size = GetFileSize(file_name);
53+
54+
std::vector<char> buffer (file_size,0);
55+
f.read(&buffer[0], buffer.size());
56+
57+
auto blob = std::make_shared<Blob>(&buffer[0], buffer.size());
58+
59+
auto stamp_j = std::make_shared<StampJSON>();
60+
std::string s = stamp_j->ExtractStr(blob);
61+
62+
printf("%s\n", s.c_str());
63+
64+
}

console_demo/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmux new-session "bash _run.sh"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy