Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node children #9

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
253ab1c
Defragmenting code
skhare-r7 Aug 18, 2019
077c456
Exposing free and used blocks in hive
skhare-r7 Aug 28, 2019
488183c
This commit works, defragments the hive. Changes needed in addition t…
skhare-r7 Aug 28, 2019
3a78495
Avoiding assertion for duplicated blocks
skhare-r7 Oct 4, 2019
4a087b6
Increasing MAX_SUBKEYS limit based on observed SxS registries
skhare-r7 Oct 18, 2019
bf7636f
DCA-18117 Added ocaml changes for building calc-hash method
mgarewal-r7 Dec 18, 2019
b1f85d9
Fixed conflicts
mgarewal-r7 Dec 18, 2019
f454d70
DCA-18117 Modified hivex-internal.h & write.c to match deframenting b…
mgarewal-r7 Dec 18, 2019
f8c5c28
DCA-18117 Added remaining methods to ocaml generator - only for hivex…
mgarewal-r7 Dec 19, 2019
e72d8cd
DCA-18117 Fixed warnings & type errors
mgarewal-r7 Dec 20, 2019
1541639
DCA-18117 Modified defragment hive_h arg name
mgarewal-r7 Dec 20, 2019
fd60722
DCA-18117 Changed RVoid type to void
mgarewal-r7 Dec 20, 2019
91f2507
DCA-18117 modified datatypes & fixed method name
mgarewal-r7 Dec 20, 2019
d0a36fe
DCA-18117 Corrected calc_hash method name
mgarewal-r7 Dec 20, 2019
31ec6ec
DCA-18117 Added docker file to build hivex
mgarewal-r7 Jan 24, 2020
78b8c3b
DCA-18117 library dependency fixes
mgarewal-r7 Jan 24, 2020
f9b4712
DCA-18117 Removed calc_hash from generator file
mgarewal-r7 Jan 24, 2020
fc23734
DCA-18117 Removed trailing backslash after package installs in Docker…
mgarewal-r7 Jan 24, 2020
307d14a
DCA-18117 Fixed sed command in dockerfile
mgarewal-r7 Jan 24, 2020
18a0b86
DCA-18117 Fixed working directory in dockerfile
mgarewal-r7 Jan 24, 2020
e26ec0b
DCA-18117 reverted name change for calc_hash method & Stdlib.stdout i…
mgarewal-r7 Jan 27, 2020
b62c891
DCA-18117 Modified method name to hivex_allocate_block in write.c
mgarewal-r7 Jan 27, 2020
f5663e7
DCA-18117 Fixed typo in dockerfile
mgarewal-r7 Jan 27, 2020
9eb01c3
DCA-18117 Modified allocate_block argument to name id
mgarewal-r7 Jan 27, 2020
82dc629
DCA-18117 Modified argument in allocate_block to pointer to id
mgarewal-r7 Jan 27, 2020
a965890
DCA-18117 Removed generator method for allocate_block
mgarewal-r7 Jan 27, 2020
ec0e5c4
DCA-18117 Set error codes for defragment method
mgarewal-r7 Jan 29, 2020
0c0eb56
DCA-18117 removed hivex from allocate_block method name
mgarewal-r7 Jan 29, 2020
0dfd5bd
DCA-18117 modified method name in handle.c - allocate_block
mgarewal-r7 Jan 29, 2020
08a3a57
DCA-18117 modified defragment argument
mgarewal-r7 Jan 30, 2020
a59a2f1
DCA-18117 Changed defragment method name
mgarewal-r7 Jan 31, 2020
180b88c
DCA0-18117 Removed variables: RVoid,AChar,ASize,AVoid from ocaml gene…
mgarewal-r7 Jan 31, 2020
0da0ed5
DCA-18117 reverted defragment method name change
mgarewal-r7 Jan 31, 2020
6b250ba
DCA-18117 removed ocaml edits text file
mgarewal-r7 Jan 31, 2020
0861266
DCA-18117 Reverted HIVEX_MAX_VALUES constant value & underscore namin…
mgarewal-r7 Feb 4, 2020
eee4c75
DCA-18117 removed trailing white space
mgarewal-r7 Feb 4, 2020
fd9e93b
DCA-18117 fixed white space in write.c
mgarewal-r7 Feb 4, 2020
1b954bd
Merge pull request #1 from rapid7/DCA-18117
skhare-r7 Feb 4, 2020
a0cf568
DCA-18117 - removed branch checkout in dockerfile
mgarewal-r7 Feb 4, 2020
5b0bc41
Merge pull request #2 from rapid7/dockerfile-hivex
mgarewal-r7 Feb 4, 2020
d9a4c4a
Removing big data. Ignoring fixing sk when it is invalid
skhare-r7 Feb 13, 2020
b8b56be
Merge pull request #3 from rapid7/fix_sk_db_issue
mgarewal-r7 Feb 14, 2020
636a415
Removing sk from defragmenting, ignoring it in add node
skhare-r7 Feb 18, 2020
ab53465
Merge branch 'master' into remove_sk_from_def
skhare-r7 Feb 18, 2020
026e7e7
Merge pull request #4 from rapid7/remove_sk_from_def
skhare-r7 Feb 18, 2020
0ba3718
Returning 0 on proper skl fix
skhare-r7 Mar 2, 2020
fa15dab
Merge pull request #5 from rapid7/fix_skl
skhare-r7 Mar 2, 2020
e9334ad
Hard coded methods for adding & deleting children
mgarewal-r7 Jul 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
FROM ubuntu

RUN apt-get update && apt-get install -y \
apt-utils \
gcc \
curl \
make \
automake \
autoconf \
git \
libtool \
pkg-config \
ocaml \
m4 \
libreadline5 \
gettext \
autopoint \
cpio \
gperf \
libxml2-utils \
mkisofs \
xz-utils \
flex \
valgrind \
psmisc \
bison \
libpcre3-dev \
libaugeas0 \
libaugeas-dev \
libmagic1 \
libmagic-dev \
libjansson4 \
libjansson-dev \
systemd-journal-remote \
libtsk-dev \
libyara-dev \
supermin \
qemu \
python \
python3-dev \
perl \
libperl-dev

RUN rm /usr/bin/python && ln -s /usr/bin/python3 /usr/bin/python

# build hivex
RUN cpan install Test::More ExtUtils::MakeMaker IO::Stringy
RUN git clone https://github.com/rapid7/hivex.git /root/hivex
WORKDIR "/root/hivex"
RUN ./autogen.sh
RUN sed -i 's/extern int hivex_node_set_value (hive_h \*h, hive_node_h node, const hive_set_value \*val, int flags);/extern int hivex_node_set_value (hive_h *h, hive_node_h node, const hive_set_value *val, int flags);extern void calc_hash (const char *type, const char *name, void *ret);extern size_t allocate_block (hive_h *h, size_t seg_len, const char id[2]);/g' /root/hivex/lib/hivex.h
RUN make
RUN make install

# build the python bindings (not sure if this is necessary)
WORKDIR "python"
RUN make
RUN make install

# had this for testing, not necessary to explicitly build perl
#WORKDIR "../perl"
#RUN make
#RUN make install

#ADD HKEY_LOCAL_MACHINE_SOFTWARE.hiv /root/hivex/regedit <-- example on how to include local file into the docker image

#older stuff to build all of libguestfs. dont think we need this.
#RUN git clone https://github.com/libguestfs/libguestfs.git /root/libguestfs
#WORKDIR "/root/libguestfs"
#RUN ./autogen.sh
#RUN make


114 changes: 107 additions & 7 deletions generator/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,22 @@ stored in C<node>. If the key does not already exist, then a
new key is added. Key matching is case insensitive.

C<node> is the node to modify.";

"free_bytes", (RSize, [AHive]),
"calculate free bytes",
"\
Hivex free bytes.";

"used_bytes", (RSize, [AHive]),
"calculate hive used bytes",
"\
Hivex used bytes.";

"defragment", (RInt32, [AHive; AString "name"]),
"defragment hives",
"\
Allocate free bytes & defragment.";

]

let f_len_exists n =
Expand Down Expand Up @@ -683,7 +699,7 @@ let check_functions () =
(* Check short descriptions. *)
List.iter (
fun (name, _, shortdesc, _) ->
if shortdesc.[0] <> Char.lowercase shortdesc.[0] then
if shortdesc.[0] <> Char.lowercase_ascii shortdesc.[0] then
failwithf "short description of %s should begin with lowercase." name;
let c = shortdesc.[String.length shortdesc-1] in
if c = '\n' || c = '.' then
Expand Down Expand Up @@ -910,6 +926,8 @@ struct hivex_visitor {

extern int hivex_visit (hive_h *h, const struct hivex_visitor *visitor, size_t len, void *opaque, int flags);
extern int hivex_visit_node (hive_h *h, hive_node_h node, const struct hivex_visitor *visitor, size_t len, void *opaque, int flags);
extern int hivex_node_add_children(hive_h *h, hive_node_h parent, const char **names, int num_names);
extern int hivex_node_delete_children(hive_h *h, hive_node_h* nodes, int num_nodes);

";

Expand Down Expand Up @@ -1513,7 +1531,9 @@ and generate_linker_script () =

let globals = [
"hivex_visit";
"hivex_visit_node"
"hivex_visit_node";
"hivex_node_add_children";
"hivex_node_delete_children"
] in

let functions =
Expand Down Expand Up @@ -2187,7 +2207,7 @@ XSLoader::load ('Win::Hivex');

List.iter (
fun (_, flag, _) ->
pr "\n [%s => 1,]" (String.lowercase flag)
pr "\n [%s => 1,]" (String.lowercase_ascii flag)
) open_flags;

pr ")
Expand Down Expand Up @@ -2217,7 +2237,7 @@ sub open {
List.iter (
fun (n, flag, description) ->
pr " # %s\n" description;
pr " $flags += %d if $flags{%s};\n" n (String.lowercase flag)
pr " $flags += %d if $flags{%s};\n" n (String.lowercase_ascii flag)
) open_flags;

pr "\
Expand Down Expand Up @@ -2956,6 +2976,84 @@ get_values (PyObject *v, py_set_values *ret)
return 0;
}

static PyObject *
py_hivex_node_add_children (PyObject *self, PyObject *args)
{
PyObject *py_r;
hive_node_h r;
hive_h *h;
PyObject *py_h;
long parent;
PyObject *names_obj;
int num_children = 0;
char const **names = NULL;

if (!PyArg_ParseTuple (args, (char *) \"OlO:hivex_node_add_children\", &py_h, &parent, &names_obj))
return NULL;
h = get_handle (py_h);
PyObject *iter = PyObject_GetIter(names_obj);
if (!iter) { return NULL; } //Not a list?
for(;;) {
PyObject *next = PyIter_Next(iter);
if (!next) break;
if (!PyUnicode_Check(next)){ return NULL; } // Non unicode string passed?
num_children++;
names = realloc (names, sizeof(char*) * num_children);
const char* name = PyUnicode_AsUTF8(next);
names[num_children-1] = name;
}
r = hivex_node_add_children (h, parent, names);
//TODO: What else needs to be freed?
free(names);
free(iter);
if (r == -1) {
PyErr_SetString (PyExc_RuntimeError,
strerror (errno));
return NULL;
}
Py_INCREF (Py_None);
py_r = Py_None;
return py_r;
}

static PyObject *
py_hivex_node_delete_children (PyObject *self, PyObject *args)
{
PyObject *py_r;
int r;
hive_h *h;
PyObject *py_h;
PyObject *nodes_obj;
unsigned long *nodes = NULL;
int num_nodes = 0;

if (!PyArg_ParseTuple (args, (char *) \"OO:hivex_node_delete_children\", &py_h, &nodes_obj))
return NULL;
h = get_handle (py_h);
PyObject *iter = PyObject_GetIter(nodes_obj);
if (!iter) { return NULL; } //Not a list?
for(;;) {
PyObject *next = PyIter_Next(iter);
if (!next) break;
if (!PyLong_Check(next)){ return NULL; } // Non unicode string passed?
num_nodes++;
nodes = realloc (nodes, sizeof(long) * num_nodes);
long node = PyLong_AsLong(next);
nodes[num_nodes-1] = node;
}
r = hivex_node_delete_children (h, nodes, num_nodes);
//TODO: What to free?
if (r == -1) {
PyErr_SetString (PyExc_RuntimeError,
strerror (errno));
return NULL;
}

Py_INCREF (Py_None);
py_r = Py_None;
return py_r;
}

static PyObject *
put_string_list (char * const * const argv)
{
Expand Down Expand Up @@ -3260,6 +3358,8 @@ put_val_type (char *val, size_t len, hive_type t)
pr " { (char *) \"%s\", py_hivex_%s, METH_VARARGS, NULL },\n"
name name
) functions;
pr " { (char *) \"node_add_children\", py_hivex_node_add_children, METH_VARARGS, NULL },\n";
pr " { (char *) \"node_delete_children\", py_hivex_node_delete_children, METH_VARARGS, NULL },\n";
pr " { NULL, NULL, 0, NULL }\n";
pr "};\n";
pr "\n";
Expand Down Expand Up @@ -3338,7 +3438,7 @@ class Hivex(object):
def __init__ (self, filename";

List.iter (
fun (_, flag, _) -> pr ", %s = False" (String.lowercase flag)
fun (_, flag, _) -> pr ", %s = False" (String.lowercase_ascii flag)
) open_flags;

pr "):
Expand All @@ -3349,7 +3449,7 @@ class Hivex(object):
List.iter (
fun (n, flag, description) ->
pr " # %s\n" description;
pr " if %s: flags += %d\n" (String.lowercase flag) n
pr " if %s: flags += %d\n" (String.lowercase_ascii flag) n
) open_flags;

pr " self._o = libhivexmod.open (filename, flags)
Expand Down Expand Up @@ -3580,7 +3680,7 @@ get_values (VALUE valuesv, size_t *nr_values)
List.iter (
fun (n, flag, _) ->
pr " if (RTEST (rb_hash_lookup (flagsv, ID2SYM (rb_intern (\"%s\")))))\n"
(String.lowercase flag);
(String.lowercase_ascii flag);
pr " flags += %d;\n" n
) open_flags
| AUnusedFlags -> ()
Expand Down
Loading