├── LICENSE
├── README.md
├── index.php
├── page
└── index.phtml
└── php
├── converter.php
└── types.php
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 UberGuidoZ
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Ducky2HID
2 |
3 | Small PHP converter for DuckyScript ([Hak5](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-quick-reference)) to HIDScript ([P4wnP1](https://p4wnp1.readthedocs.io/)).
4 |
5 | Originally known as [ds2pp](https://github.com/d5a/ds2pp) by d5a but abandonded in Jan 2019.
6 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | [
34 | 'err' => 0,
35 | 'msg' => ''
36 | ],
37 | 'time' => 0
38 | ];
39 |
40 | $output = '';
41 |
42 | if($input !== false) {
43 | $result = $converter->convert($input, false, $types->getTypes(), false);
44 |
45 | if(isset($_POST['layout'])) {
46 | $output .= '// Layout: ' . $_POST['layout']. "\n" . 'layout("'.$_POST['layout'].'");' . "\n\n";
47 | }
48 |
49 | foreach($result['output'] as $o) {
50 | $output .= "$o\n";
51 | }
52 | }
53 |
54 | $page_content = file_get_contents('page/index.phtml');
55 |
56 |
57 | $vars = [
58 | 'input' => $input,
59 | 'output' => $output,
60 | 'input' => isset($_POST['input']) ? $_POST['input'] : '',
61 | 'error_msg' => $result['error']['err'] === 1 ? $result['error']['msg'] : '',
62 | 'execution_time' => $result['time'],
63 | 'layout' => isset($_POST['layout']) ? $_POST['layout'] : ''
64 | ];
65 |
66 | $page_lines = explode("\n", $page_content);
67 | $ignore = false;
68 | foreach($page_lines as $line) {
69 | foreach($vars as $key => $val) {
70 | $line = str_replace("{{ $key }}", $val, $line);
71 | }
72 |
73 | $t = trim($line);
74 | if($t == '{{ if_output_convert }}') {
75 | if($input === false) {
76 | $ignore = true;
77 | }
78 | continue;
79 | }
80 |
81 | if($t == '{{ end_if_output_convert }}') {
82 | $ignore = false;
83 | continue;
84 | }
85 |
86 | if($t == '{{ if_error }}') {
87 | if($result['error']['err'] === 0) {
88 | $ignore = true;
89 | }
90 | continue;
91 | }
92 |
93 | if($t == '{{ end_if_error }}') {
94 | $ignore = false;
95 | continue;
96 | }
97 |
98 | if($ignore) {
99 | continue;
100 | }
101 |
102 | echo "$line\n";
103 | }
--------------------------------------------------------------------------------
/page/index.phtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
15 |
16 | Ducky Script -> P4wnP1 (aloa)
17 |
18 |
28 |
29 |
30 |
31 |
38 |
39 |
40 |
41 |
42 |
43 | Input
44 |
45 |
46 |
47 |
68 |
69 |
70 |
71 | {{ if_output_convert }}
72 |
73 |
74 |
75 | {{ if_error }}
76 |
{{ error_msg }}
77 | {{ end_if_error }}
78 |
79 |
80 |
81 | Output
82 |
83 |
84 |
85 |
86 |
87 |
88 |
Execution time: {{ execution_time }} ms
89 |
90 | {{ end_if_output_convert }}
91 |
92 |
93 |
94 |
95 |
96 |
101 |
102 |
--------------------------------------------------------------------------------
/php/converter.php:
--------------------------------------------------------------------------------
1 | [
20 | 'err' => 0,
21 | 'msg' => ''
22 | ],
23 | 'output' => [
24 |
25 | ],
26 | 'time' => 0
27 | ];
28 |
29 | $currentLine = 0;
30 | foreach(explode("\n", $input) as $line) {
31 |
32 | // Count lines
33 | $currentLine++;
34 |
35 | $line = trim($line);
36 |
37 | // Insert newline
38 | if(strlen($line) === 0) {
39 | if($newLine === true) {
40 | array_push($result['output'], '');
41 | }
42 | continue;
43 | }
44 |
45 | $arg = $line;
46 | $val = "";
47 |
48 | // Val
49 | if(\strpos($line, ' ') !== false) {
50 | $arg = explode(' ', $line)[0];
51 | $val = ltrim(substr($line, strpos($line, ' ')));
52 | }
53 |
54 | $foundType = false;
55 | $foundIndex = '';
56 |
57 | // Check types
58 | foreach($types as $typeKey => $typeVal) {
59 | $args = [];
60 |
61 | // Multiple types
62 | foreach(explode('|', $typeKey) as $splitted) {
63 | array_push($args, $splitted);
64 | }
65 |
66 | if(in_array($arg, $args)) {
67 | $foundIndex = $typeKey;
68 | $foundType = true;
69 | break;
70 | }
71 | }
72 |
73 | if($foundType === false) {
74 |
75 | if($cancelUnknown === true) {
76 | $result['error']['err'] = 1;
77 | $result['error']['msg'] = '[L: ' . $currentLine . ']: Type "' . $arg . '" not found!';
78 |
79 | break;
80 | }
81 |
82 | continue;
83 | }
84 |
85 | $settings = $types[$foundIndex];
86 |
87 | // Normal type
88 | $str = $settings;
89 |
90 | // Apply regex?
91 | if(is_array($settings)) {
92 | $str = $settings[0];
93 |
94 | // Check regex ?
95 | if(isset($settings['regex'])) {
96 | $regex = $settings['regex'];
97 |
98 | if(preg_match($regex, $val)) {
99 | $result['error']['err'] = 1;
100 | $result['error']['msg'] = '[L: ' . $currentLine . ']: Regex "' . $regex . '" failed for value "' . $val . '"!';
101 |
102 | break;
103 | }
104 | }
105 |
106 | // Execute function
107 | if(isset($settings['function'])) {
108 | $funct_name = $settings['function'];
109 |
110 | if(!is_callable(['Types', $funct_name])) {
111 | $result['error']['err'] = 1;
112 | $result['error']['msg'] = '[L: ' . $currentLine . ']: Function "' . $funct_name . '" not found! (Backend-Bug)';
113 |
114 | break;
115 | }
116 |
117 | $funct_res = call_user_func(['Types', $funct_name], $arg, $val, $result['output']);
118 |
119 | // String => ERROR / Continue
120 | if(is_string($funct_res)) {
121 | if($funct_res == 'OK') {
122 | continue;
123 | }
124 |
125 | $result['error']['err'] = 1;
126 | $result['error']['msg'] = '[L: ' . $currentLine . ']: ["' . $funct_name . '"]: ' . $funct_res;
127 |
128 | break;
129 | }
130 |
131 | // Array => New result
132 | if(is_array($funct_res)) {
133 | $result['output'] = $funct_res;
134 | continue;
135 | }
136 | }
137 | }
138 |
139 | // Replace types
140 | $str = str_replace('{arg}', $arg, $str);
141 | $str = str_replace('{val}', $val, $str);
142 |
143 | $i = 0;
144 | foreach(explode('|', $foundIndex) as $splitted) {
145 | $i++;
146 | $str = str_replace('{arg|'.$i.'}', $splitted, $str);
147 | }
148 |
149 | if(strlen($val) > 0) {
150 | $str = str_replace('{space}', ' ', $str);
151 | } else {
152 | $str = str_replace('{space}', '', $str);
153 | }
154 |
155 | array_push($result['output'], $str);
156 | }
157 |
158 | // Execution time
159 | $result['time'] = (microtime(true) - $executionStartTime);
160 |
161 | return $result;
162 | }
163 |
164 | }
--------------------------------------------------------------------------------
/php/types.php:
--------------------------------------------------------------------------------
1 | '// {val}',
9 |
10 | 'DELAY' => [
11 | 'delay({val});',
12 | 'regex' => '/[^0-9]/'
13 | ],
14 |
15 | 'STRING' => [
16 | 'type("{val}");'
17 | ],
18 |
19 | "WINDOWS|GUI" => [
20 | 'press("LEFT_GUI{space}{val}");'
21 | ],
22 |
23 | 'MENU|APP|SHIFT|ALT|CONTROL|CTRL' => [
24 | 'press("{arg}{space}{val}");',
25 | 'regex' => '/[^A-Za-z]/'
26 | ],
27 |
28 | 'DOWNARROW|DOWN|DOWN_ARROW' => [
29 | 'press("DOWN_ARROW");'
30 | ],
31 |
32 | 'LEFTARROW|LEFT|LEFT_ARROW' => [
33 | 'press("LEFT_ARROW");'
34 | ],
35 |
36 | 'RIGHTARROW|RIGHT|RIGHT_ARROW' => [
37 | 'press("RIGHT_ARROW");'
38 | ],
39 |
40 | 'UPARROW|UP|UP_ARROW' => [
41 | 'press("UP_ARROW");'
42 | ],
43 |
44 | 'ENTER' => [
45 | 'press("{val}");'
46 | ],
47 |
48 | 'REPEAT' => [
49 | '',
50 | 'function' => 'func_repeat',
51 | 'regex' => '/[^0-9]/'
52 | ]
53 | ];
54 |
55 | /**
56 | * For the 'REPEAT' - command
57 | */
58 | public static function func_repeat($arg, $val, &$arr) {
59 |
60 | if(count($arr) === 0) {
61 | return 'No previous commands!';
62 | }
63 |
64 | $index = count($arr) - 1;
65 | $lastCommand = $arr[$index];
66 |
67 | unset($arr[$index]);
68 | array_push($arr, "for (var i = 0; i < $val; i++) {\n $lastCommand\n}");
69 |
70 | return $arr;
71 | }
72 |
73 | public function getTypes() {
74 | return $this->types;
75 | }
76 | }
--------------------------------------------------------------------------------