readme usage
This commit is contained in:
parent
af359ae4d1
commit
889812f505
2 changed files with 27 additions and 5 deletions
11
README.md
11
README.md
|
@ -1,3 +1,12 @@
|
|||
# command_injector
|
||||
|
||||
Simple command injector for html files(also copies them to a different folder, maintaining the original files!)
|
||||
Simple command injector for html files(also copies them to a different folder, maintaining the original files!)
|
||||
|
||||
## Usage
|
||||
|
||||
Simply put a `<INJECT>%COMMAND%</INJECT>` in your html files,
|
||||
and it will copy all other files(except hidden ones).
|
||||
|
||||
then compile using `cargo run -- from_dir to_dir [-r]`
|
||||
|
||||
or directly calling the compiled bin `injector from_dir to_dor [-r]`
|
21
src/main.rs
21
src/main.rs
|
@ -64,7 +64,13 @@ fn inject_file(file: &Path, output: &Path) {
|
|||
}
|
||||
match from_utf8(&buf[..len]) {
|
||||
Ok(s) => {
|
||||
write_injection(s, &mut out, &mut inp, file.parent().unwrap().as_os_str().to_str().unwrap());
|
||||
write_injection(
|
||||
s,
|
||||
&mut out,
|
||||
&mut inp,
|
||||
file.parent().unwrap().as_os_str().to_str().unwrap(),
|
||||
file.file_name().unwrap().to_str().unwrap(),
|
||||
);
|
||||
},
|
||||
Err(e) => {
|
||||
if e.valid_up_to() == 0 {
|
||||
|
@ -74,7 +80,13 @@ fn inject_file(file: &Path, output: &Path) {
|
|||
let s = unsafe { from_utf8_unchecked(&buf[..e.valid_up_to()]) };
|
||||
inp.seek(SeekFrom::Current(-1 * (len - e.valid_up_to()) as i64)).unwrap();
|
||||
|
||||
write_injection(s, &mut out, &mut inp, file.parent().unwrap().as_os_str().to_str().unwrap());
|
||||
write_injection(
|
||||
s,
|
||||
&mut out,
|
||||
&mut inp,
|
||||
file.parent().unwrap().as_os_str().to_str().unwrap(),
|
||||
file.file_name().unwrap().to_str().unwrap(),
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -99,7 +111,7 @@ fn inject_file(file: &Path, output: &Path) {
|
|||
out.flush().expect(&format!("Cannot flush file {:?}", output.as_os_str()));
|
||||
}
|
||||
|
||||
fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str) {
|
||||
fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str, cfile: &str) {
|
||||
let tag : &str = "<INJECT>";
|
||||
let ctag : &str = "</INJECT>";
|
||||
|
||||
|
@ -115,6 +127,7 @@ fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str) {
|
|||
.arg(com)
|
||||
.env("HOME", unsafe { &HOME_DIR })
|
||||
.env("CURRENT", cfolder)
|
||||
.env("FILE", cfile)
|
||||
.output();
|
||||
|
||||
let com = match com {
|
||||
|
@ -123,7 +136,7 @@ fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str) {
|
|||
};
|
||||
|
||||
out.write(com.as_bytes()).unwrap();
|
||||
write_injection(post, out, inp, cfolder);
|
||||
write_injection(post, out, inp, cfolder, cfile);
|
||||
}
|
||||
else if s.contains(tag) {
|
||||
// We have the first tag but not the second, so we want to go back in the input file..
|
||||
|
|
Loading…
Reference in a new issue