1-------------------------------------------------------------------------------
2NETSCRIPT: documentation support on syntax, ruleset, and environment help.
3AUTHOR: v9@fakehalo.deadpig.org, fakehalo.deadpig.org. [ihadnihn]
4TOC: syntax, ruleset, environment, module, security, eof.
5-------------------------------------------------------------------------------
6
7
8 __ _ __
9 _ __ ___| /_ ___ ___ _ __(_)_ __ | /_ (portable/multi-platform) lightwei-
10 | '_ \./ _ \ __/ __)/ __| '__| | '_ \| __) ght tcp/udp socket scripting. int-
11 | | | | ._/ |_(__ \ (__| | | | |_) ) |_ ended for (non-)experienced person-
12 |_| |_|\___|\__|___/\___|_| |_| .__/ \__) s to be able to use to automate si-
13 [TCP / UDP socket scripting] |_| [1.7.1] tuations, built on a word-to-word
14 ruleset response system. includes
15 wildcard support, character replacement, random replacement, argument inclusi-
16 on, server timeout, initial send, display altering, multiple character dump f-
17 ormats, telnet protocol support, logging, program to socket dumping, executab-
18 le ruleset support, reverse binding, module support, data truncation, data fo-
19 rmatting, permission options, virtual hosting support, history storage, dynam-
20 ic storage variables, directory placement, character omitting, timed rules, b-
21 ackground support, syslog support, routing support, socket options, interacti-
22 ve mode, and a graphical user interface among other things.
23
24
25******************
26***** SYNTAX *****
27******************
28
29there are a good amount of command line options for netscript. so, they need
30some sort of explaination. (minimal as it may seem)
31
32NOTE: the required arguments to run are: -r or -s or -f, -h or -b, and -p.
33
34 -r <argument>
35 this will take the supplied argument as the ruleset file.
36
37 -h <argument>
38 this will take the supplied argument as the hostname, or ip to connect to.
39 (if you use commas it will connect to each remote host in order. example:
40 ./netscript -r rules -h server1.com,server2.com -p 1)
41
42 -p <argument>
43 this will take the supplied argument as the port to connect to, or bind
44 as. also, you may use services defined in /etc/services as ports. for
45 example: "finger", "http", and "ftp".
46
47 -# <data>
48 will statically define the dynamic variable. storing the following data
49 in ${#}, and making it an unchangeable variable. (# = a value between 0-9)
50
51 -i <argument>
52 this will take the supplied argument as initial data to send to the remote
53 host once connected. also, if a "?" is used as the argument it will take
54 dynamic information from standard input once connected.
55
56 -m <argument>
57 this will change the current working directory of netscript to the
58 supplied argument. this is handled before anything else. (except -M)
59
60 -M <argument>
61 this will change the root directory of netscript to the supplied argument.
62 this is handled before anything else. (superuser only. also note, this
63 will severely cripple netscript, use only under special circumstances)
64
65 -R <argument>
66 this will take the supplied argument as a route hostname, or ip to use.
67 this means information that occurs on the main connection will be passed
68 over to this hostname/ip. the virtual hostname(-q option), if defined,
69 will be applied to this option. also note, if the connection is dropped,
70 it will not notify, it will remain silent(unless done via a ruleset
71 request). (this function only connects out)
72
73 -k <argument>
74 this will take the supplied argument as a port to connect to on the route
75 hostname/ip.
76
77 -u <argument>
78 this will change the id permissions of netscript(uid/gid/groups). the
79 format is "user[.group]". but, if just "user" is supplied it will work,
80 it will just use the group id of the user id. the id permissions change
81 right after a successful connection. but, set before taking any input, or
82 sending any output. (this will not conflict with privileged running of
83 netscript, security would still remain)
84
85 -q <argument>
86 this will take the supplied argument as a virtual hostname, or ip to use.
87 (note: this has priority over the environmental variable usage)
88
89 -o <argument>
90 this will take the supplied argument as a set of character(s) to omit from
91 socket reading. (will omit the characters before any contact, at the same
92 level as the -P option)
93
94 -S <argument>
95 this will wait the alloted time supplied by the argument before processing
96 incoming data. can be used in conjunction with -U. (in seconds)
97
98 -U <argument>
99 this will wait the alloted time supplied by the argument before processing
100 incoming data. can be used in conjunction with -S. (in useconds)
101
102 -t <argument>
103 this will close the session after the alloted time supplied by the
104 argument, the countdown starts once conncted to the server.
105
106 -Q <argument>
107 this will take the supplied argument to set socket option(s) within
108 netscript. the format for this option is "value1,value2,value3" separated
109 by a colon, for multiple socket options. the first value is for the
110 socket used, to apply the option to the socket; 0 is for the connecting
111 in/out socket(client socket). 1 is for the binded socket(server socket).
112 2 is for the route socket(-R option). the second value is for the option
113 itself(options are listed below). the third, and final value is to set
114 the value of the second value.
115
116 here is a generalized list of values that can be used for the socket
117 option(second value used): 1=SO_DEBUG, 2=SO_REUSEADDR, 3=SO_TYPE,
118 4=SO_ERROR, 5=SO_DONTROUTE, 6=SO_BROADCAST, 7=SO_SNDBUF, 8=SO_RCVBUF,
119 9=SO_KEEPALIVE, 10=SO_OOBINLINE, 11=SO_NO_CHECK, 12=SO_PRIORITY,
120 13=SO_LINGER, 14=SO_BSDCOMPAT, 15=SO_REUSEPORT, 16=SO_PASSCRED,
121 17=SO_PEERCRED, 18=SO_RCVLOWAT, 19=SO_SNDLOWAT, 20=SO_RCVTIMEO,
122 21=SO_SNDTIMEO.
123
124 for example, "-Q 1,2,1:1,15,1" would have the following effect in C:
125 {
126 int i=1;
127 setsockopt(bindsocketfd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
128 setsockopt(bindsocketfd, SOL_SOCKET, SO_REUSEPORT, &i, sizeof(i));
129 }
130 if this example displays the error message "internal setting of socket
131 option failed", the system probably does not support SO_REUSEPORT.
132
133 note: this option will not support all socket options, only socket options
134 that are intended to be used in enabled/disabled, or numeric situations.
135 considering this option only passes values in the form of an integer.
136
137 -l <argument>
138 this will take the supplied argument as a file to log input/output data.
139
140 -G <argument>
141 this will display the argument as the title for the gui. this is for use
142 with gui mode.
143
144 -+ <argument>
145 this will take the argument as a value to change the length of the
146 pulled down gui. this is for use with the non-generic gui only.
147
148 -# <argument>
149 this will take the argument as a hex triplet to set as the color of the
150 foreground text, for use with gui mode. ("#" precursor is not needed)
151
152 -K <argument>
153 this will define alternate button labels for the netscript gui. the
154 argument format is "label1:label2:label3"; where "label1" is the exit
155 button, "label2" is the clear screen button, and "label3" is the pulldown
156 check button(only in non-generic gui). this is for use with the gui mode.
157
158 -= <argument>
159 this will define alternate button tabs for the netscript (ncurses) gui.
160 the argument format is "label1:label2"; where "label1" is the output tab,
161 and "label2" is the input tab. this is for use with the (ncurses) gui
162 mode. (this is optional upon compile)
163
164 -e <argument>
165 this will take the supplied argument as a program to dump to the remote
166 host once connected.
167
168 -E <argument>
169 precurse data to attach for each line dumped. this works in conjuntion
170 with the -e option, and the $= variable.
171
172 -O <argument>
173 this will use an alternate shell to execute third party programs. it
174 will override that of the $SHELL environmental variable, or the default.
175
176 -x <argument>
177 this will kill the program if the dumping of the program supplied with the
178 -e option exceeds the time allowed(idle time) with the supplied argument.
179 (3 is the internal default)
180
181 -X
182 this will kill netscript after the dumping of the program to the remote
183 host.
184
185 -a
186 this will allow interactive use of programs. (if you use this, be on guard
187 of what you are doing)
188
189 -f
190 this will launch a third party editor to make a temporary ruleset. if
191 the -r option is used in conjunction with -f, it will take that file as
192 a ruleset to edit, instead of a temporary file. it will not remove the
193 file upon completion, if the -r option is used.
194
195 -@
196 this will switch netscript to the UDP protocol. this may, or may not
197 effect the performance of netscript. since connections do not actually
198 exist, the connection will never be dropped unless invoked via the
199 ruleset. (the UDP protocol allows for packet loss)
200
201 -^
202 this will switch the route host to the UDP protocol.
203
204 -B
205 sends netscript to the background. (forked)
206
207 -n
208 this will disable display of any outgoing data, will not effect logging.
209
210 -N
211 this will disable display of any incoming data, will not effect logging.
212
213 -j
214 this will disable routed sending of outgoing data. (route support)
215
216 -J
217 this will disable routed sending of incoming data. (route support)
218
219 -F
220 this will disable display of the arrow precursors, will not effect
221 logging.
222
223 -I
224 this will reocnnect to the remote host, or rebind to the port specified.
225 when disconnected.
226
227 -s
228 this will take the ruleset from standard input, instead of a file.
229
230 -b
231 this will bind to the supplied port instead of connecting out, like a
232 reversed mode.
233
234 -g
235 enables the gui frontend of netscript, once launched. (use twice for
236 generic version) also, if launched via a link from ./gnetscript,
237 netscript will automatically apply the -g option.
238
239 -W
240 this will automatically start the (non-generic) gui pulled down.
241
242 -_
243 this will switch the console display of netscript to ncurses.
244 also, if launched via a link from ./nnetscript, netscript will
245 automatically apply the -_ option. (this is optional upon compile)
246
247 -Z
248 system logging support, for when netscript is running at a syslog
249 accessible level. this will log initialization, execution of third party
250 programs, reading of files, writing to files, ip/port, id changes, and
251 exit notification. (the pid shown in the syslog line will be the main pid,
252 even if it is not the current pid running that logged the line, this will
253 help to keep information together by reference of the pid)
254
255 -T
256 this will attempt to reply to telnet option requests. this will also
257 change the handling of incoming data if turned on, and has received one,
258 or more telnet option(s).
259
260 -y
261 will dump raw socket data to standard error. this is for use with the
262 telnet option(-T). it will dump the raw incoming, and outgoing socket
263 data in an effort to correct segment breaking. it will not change the
264 effects it has on the ruleset, it will still handle in segments. (this
265 will force other options to be disabled, and/or enabled. this includes
266 having telnet mode(-T) on. also, this will override normal logging
267 routines)
268
269 -Y
270 will dump raw socket data to standard output. this is for use with the
271 telnet option(-T). it will dump the raw incoming, and outgoing socket
272 data in an effort to correct segment breaking. it will not change the
273 effects it has on the ruleset, it will still handle in segments. (this
274 will force other options to be disabled, and/or enabled. this includes
275 having telnet mode(-T) on. also, this will override normal logging
276 routines)
277
278 -z
279 this will disable display for telnet option replies, with the -T option.
280
281 -L
282 displays the value of each line as a precursor. (this option will force
283 disabled word wrapping)
284
285 -H
286 this will display input/output in hex form, instead of character form.
287
288 -D
289 this will display input/output in decimal form, instead of character form.
290
291 -w
292 this will disable wordwrap support for input/output displaying.
293
294 -P
295 this will disable reading of non-printable characters from the socket, the
296 -T option is processed before this, so it will be un-effected.
297
298 -c
299 this will disable the display of initial connection notification
300 information.
301
302 -C
303 this will disable the display of ruleset information that is not required
304 to know. (basically, this cuts down on excess screen junk)
305
306 -A
307 this will disable the display of all netscript prompts containing
308 information. (for example, "./netscript: so, and so." will not be shown)
309
310 -d
311 this will display a shortened definition list of ruleset variables, and
312 environmental variables used with netscript.
313
314 -v
315 this will display the version, and id value of netscript(format 1) and
316 exit.
317
318 -V
319 this will display the version, and id value of netscript(format 2) and
320 continue.
321
322 --list [argument:argument:...] (must be the first, and only argument used)
323 this option is for use with command line use only. lists, and allows
324 usage of ruleset(s) via a file list. the argument(s), if supplied,
325 will be taken as alternative directory(s) to list, instead of the current
326 working directory.
327
328 --hist [argument] (must be the first, and only argument used)
329 this option is for use with command line use only. lists, and allows
330 usage of past arguments from the netscript history file. (~/.nshistory)
331 if an argument is provided it will be taken as the history line value to
332 use for arguments. but, if the argument provided is "clear" it will
333 delete the history file, if it exists. (use $20/$032's for spaces on most
334 parameters to avoid issues with multi-space arguments, when using
335 netscript in general)
336
337
338*******************
339***** RULESET *****
340*******************
341
342netscripts ruleset, the whole point of netscript, is to check for given input
343from the server that matches the input in the ruleset. the structure of the
344ruleset is a simple per-line format, one line for input, and one for output.
345this is illustrated like so:
346
347file.ruleset:
348-------------------------------------------------------------------------------
349# example of basic ruleset.
350input given 1
351output responded 1
352input given 2
353output responded 2
354-------------------------------------------------------------------------------
355
356if this ruleset was used it would respond "output responded 1" if "input given
3571" was sent to the socket, and "output responded 2" if "input given 2" was sent
358to the socket. this ruleset is a direct match situation.
359
360if you want to be able to run the ruleset +x/executable, you can format the
361ruleset like so:
362
363file.ruleset:
364-------------------------------------------------------------------------------
365#!/path/to/netscript
366#?-h host.com -p 1
367# example of basic ruleset.
368input given 1
369output responded 1
370input given 2
371output responded 2
372-------------------------------------------------------------------------------
373
374"#!"(on the first line) followed by the direct path to netscript, and
375"#?"(on the second line) followed by the arguments desired will use the
376supplied information as netscript arguments. then you can chmod +x the
377ruleset to run it.
378
379if information being received may not be a static value you can use match
380variables to check for matches with data from there remote host, here is the
381list of variables that can be used, with an explaination:
382
383NOTE: these are ONLY for use with input responses, not output. also, these
384match variables require a word slot to use correctly(spaces in-between).
385
386
387 "$;" (must be the first data on the output line, needs data)
388 when this is placed at the beginning of the line it will allow a match,
389 as long as what is placed after the variable does not match the incoming
390 data.
391
392 example:
393 $;001 $*
394 USER test
395
396 so, if those two lines were in a ruleset, and the remote host sent "001 "
397 followed by anything, or nothing the ruleset would not send "USER test".
398 (it will only send if it did not match)
399
400
401 "$*"
402 when this is placed at the end of the line(with a space before) it will
403 allow a match as long as anything before its use matched.
404
405 example:
406 001 $*
407 USER test
408
409 so, if those two lines were in a ruleset, and the remote host sent "001 "
410 followed by anything, or nothing the ruleset would send "USER test".
411
412
413 "$?"
414 when this is placed at the end of the line(with a spaces) it will
415 allow a match as long as input has a value, and isn't non-existent.
416
417 example:
418 001 $? $? $*
419 USER test
420
421 so, if those two lines were in a ruleset, and the remote host sent "001 "
422 followed by two, or more words the ruleset would send "USER test".
423
424
425 "$ALPHA"
426 when this variable is placed in a line(with spaces) it will allow a match
427 as long as the corresponding word is alphabetical. (A-Za-z)
428
429 example:
430 001 $ALPHA $*
431 USER test
432
433 so, if those two lines were in a ruleset, and the remote host sent "001 "
434 followed by an alphabetical word the ruleset would send "USER test".
435
436
437 "$DIGIT"
438 when this variable is placed in a line(with spaces) it will allow a match
439 as long as the corresponding word is numerical. (0-9)
440
441 example:
442 001 $DIGIT $*
443 USER test
444
445 so, if those two lines were in a ruleset, and the remote host sent "001 "
446 followed by a numerical word the ruleset would send "USER test".
447
448
449 "$ALNUM"
450 when this variable is placed in a line(with spaces) it will allow a match
451 as long as the corresponding word is alphabetical, or numerical.
452 (A-Za-z0-9)
453
454 example:
455 001 $ALNUM $*
456 USER test
457
458 so, if those two lines were in a ruleset, and the remote host sent "001 "
459 followed by an alphabetical, or numerical word the ruleset would send
460 "USER test".
461
462
463 "$UPPER"
464 when this variable is placed in a line(with spaces) it will allow a match
465 as long as the corresponding word is upper case. (A-Z)
466
467 example:
468 001 $UPPER $*
469 USER test
470
471 so, if those two lines were in a ruleset, and the remote host sent "001 "
472 followed by a upper case word the ruleset would send "USER test".
473
474
475 "$LOWER"
476 when this variable is placed in a line(with spaces) it will allow a match
477 as long as the corresponding word is lower case. (a-z)
478
479 example:
480 001 $LOWER $*
481 USER test
482
483 so, if those two lines were in a ruleset, and the remote host sent "001 "
484 followed by a lower case word the ruleset would send "USER test".
485
486
487 "$PUNCT"
488 when this variable is placed in a line(with spaces) it will allow a match
489 as long as the corresponding word is printable/non-standard.
490
491 example:
492 001 $PUNCT $*
493 USER test
494
495 so, if those two lines were in a ruleset, and the remote host sent "001 "
496 followed by a punctuated word the ruleset would send "USER test".
497
498
499 "$CNTRL"
500 when this variable is placed in a line(with spaces) it will allow a match
501 as long as the corresponding word is control (character) word. (this is
502 more of a special situation match variable)
503
504 example:
505 001 $CNTRL $*
506 USER test
507
508 so, if those two lines were in a ruleset, and the remote host sent "001 "
509 followed by a control (character) word the ruleset would send "USER test".
510
511
512 "$PRINT"
513 when this variable is placed in a line(with spaces) it will allow a match
514 as long as the corresponding word is printable.
515
516 example:
517 001 $PRINT $*
518 USER test
519
520 so, if those two lines were in a ruleset, and the remote host sent "001 "
521 followed by a printable word the ruleset would send "USER test".
522
523
524 "$####"
525 (where # is the equivalent of a numerical value) when this variable is
526 placed in a line(with spaces) it will allow a match as long as the
527 corresponding word is equal in length with the supplied numerics. for
528 example, $0015 would match as long as the word trying to be matched is
529 equal to 15 bytes. this variable must fill all four numeric slots to be
530 recognized.
531
532
533NOTE: those are all of the input match variables. there is another type of
534variable that can be used with both input, and output. replacement variables.
535
536
537 "$REPEAT" (rule replacement, must be the only thing on the input/output line)
538 this variable will do the same thing as the corresponding input/output
539 variable does before it. if it this variable is used for the first
540 input/output rule it will be ignored and taken as common text.
541
542 example:
543 001 Test daemon.
544 USER test
545 $REPEAT
546 PASS test
547
548 so, with this example it would send "USER test", and "PASS test" when the
549 text "001 Test daemon." is received.
550
551
552 "$##" (hex replacement)
553 when this is placed anywheres in the ruleset file it will replace the hex
554 value with the character value. (where "##" is 01-FF)
555
556 example:
557 001 Test daemon$2E
558 USER test$2E
559
560 so, with this example it would exchange the two $2E's with ".". because,
561 the hex value of "2E" is ".".
562
563
564 "$###" (decimal replacement)
565 when this is placed anywheres in the ruleset file it will replace the
566 decimal value with the character value. (where "###" is 001-255)
567
568 example:
569 001 Test daemon$046
570 USER test$046
571
572 so, with this example it would exchange the two $046's with ".". because,
573 the decimal value of 046 is ".".
574
575
576 "$&" (random alphabetical replacement)
577 when this is placed anywheres in the ruleset file it will replace the
578 variable value with a random alphabetical value.
579
580 example:
581 001 Test daemon.
582 USER $&$&$&$&
583
584 so, with this example it would exchange the four $&'s with random
585 alphabetical characters. (A-Za-z)
586
587
588 "$#" (random numerical replacement)
589 when this is placed anywheres in the ruleset file it will replace the
590 variable value with a random numerical value.
591
592 example:
593 001 Test daemon.
594 USER $#$#$#$#
595
596 so, with this example it would exchange the four $#'s with random
597 numerical characters. (0-9)
598
599
600NOTE: the following are output ONLY variables, not input. most of them must
601be exact/exact start matches.
602
603
604 "$@" (must be the first data on the output line, needs data)
605 this variable will stop use of the ruleset if it is the first thing on the
606 output response line. also, if you attach anything after the variable it
607 will show the new data instead of the default hardcoded data when the
608 event occurs.
609
610 example:
611 001 Test daemon.
612 $@done using ruleset
613
614
615 "$^" (must be the first data on the output line, needs data)
616 this variable will restart use of the ruleset if it is the first thing
617 on the output response line. this variable is in conjunction with $@, to
618 restart once the signal is given. usually, for use with using the same
619 input given multiple times to send a sequence of responses. also, if you
620 attach anything after the variable it will show the new data instead of
621 the default hardcoded data when the event occurs.
622
623 example:
624 001 Test daemon.
625 $^restarted using ruleset
626
627 example 2: (how to use for multiple responses in conjunction with $@)
628 Password:
629 $-pass1
630 Password:
631 $-$@turned off, done with the first password
632 Password:
633 pass2
634 Password:
635 $^turned back on for second password to come later
636
637
638 "$:" (must be the first data on the output line, needs data)
639 this variable will stop use of the ruleset for one cycle of matching, if
640 it is the first thing on the output response line. this variable is much
641 like $^. but, this variable is better for more situations. also, if you
642 attach anything after the variable it will show the new data instead of
643 the default hardcoded data when the event occurs.
644
645 example:
646 001 Test daemon.
647 $:no more rules will be used after this point, in this cycle
648
649 example 2: (how to use for multiple responses, like $^)
650 Password:
651 $-pass1
652 Password:
653 $-$:done with first password, halting the ruleset read
654 Password:
655 $-pass2
656 Password:
657 $-$:done with second password, halting the ruleset read
658 Password:
659 $-pass3
660 Password:
661 $-$:done with third password, halting the ruleset read
662
663
664 "$!" (must be the first data on the output line, needs data)
665 this variable will close the socket if it is first thing on the output
666 response line. also, if you attach anything after the variable it will
667 show the new data instead of the default hardcoded data when the event
668 occurs.
669
670 example:
671 001 Test daemon.
672 $!incorrect test daemon type, closing socket
673
674
675 "$~" (must be the first data on the output line, needs data)
676 this variable will ask for unique information from standard input if it is
677 the first thing on the output response line. also, if you attach anything
678 after the variable it will prompt when the event occurs with the supplied
679 data.
680
681 example:
682 001 Test daemon.
683 $~enter a response
684
685
686 "$/" (must be the first data on the output line, needs data)
687 this variable is used to truncate data for use in rules to follow. if
688 only one character is provided after the variable it will truncate it.
689 if two, or more characters are provided it will take the second character,
690 and replace it with the first in the server output. this will not effect
691 the display of netscript.
692
693 example:
694 $*
695 $/.,
696 $*
697 $/-
698
699 this example would replace all periods with commas, and truncate dashes
700 for use in rules to come.
701
702
703 "$]" (must be the first data on the output line, needs data)
704 this variable is used to truncate data for use in rules to follow. this
705 variable takes the character after the variable as a point to cut the line
706 off at, and tokenizes it to the left. the variable will use the first
707 character point that occurs.
708
709 example:
710 $*
711 $].
712
713 this example would cut line at the first period for all rules to follow.
714
715
716 "$[" (must be the first data on the output line, needs data)
717 this variable is used to truncate data for use in rules to follow. this
718 variable takes the character after the variable as a point to cut the line
719 off at, and tokenizes it to the right. the variable will use the first
720 character point that occurs.
721
722 example:
723 $*
724 $[.
725
726 this example would remove everything before the first period for all
727 rules to follow.
728
729
730 "$," (must be the first data on the output line, needs data)
731 this variable is used to truncate data for use in rules to follow. this
732 variable is used with two arguments separated by a comma between two
733 numbers. the first number is taken as a start point, and the second
734 number is taken as a stop point. (note: negative values in the second
735 numeric feild will be taken as the full length of the rest of the line)
736 this will not effect the display of netscript.
737
738 example:
739 $*
740 $,0,3
741
742 this example would replace the server data with the first three bytes of
743 the server data for use in rules to come.
744
745
746 "$|" (must be the first data on the output line, needs data)
747 this variable is used to format data for use in rules to follow. this
748 will take the output/supplied line, and replace the input data with it.
749 for use in rules to come. this will not effect the display of netscript.
750
751 example:
752 001 $? daemon.
753 $|connected to a $1 daemon.
754 connected to a $? daemon.
755 $+daemon.types
756
757 this example would change the server data from "001 ??? daemon" to
758 "connectected to a ??? daemon.". then, it would append that information
759 to the file "daemon.types".
760
761
762 "$%" (must be the first data on the output line, needs data)
763 this variable will display the data after the variable for display
764 purposes.
765
766 example:
767 001 Test daemon.
768 $%Connected successfully
769
770
771 "$_" (must be the first data on the output line, needs data)
772 this variable will write to the socket like normal. except, with no
773 CR(\n) appended.
774
775 example:
776 001 Test daemon.
777 $_USER test
778
779
780 "$-" (must be the first data on the output line, needs data)
781 this variable will use the following rule only one time per connection.
782 you must have data after the variable for it to be recognized as a
783 variable.
784
785 example:
786 001 Test daemon.
787 $-USER test
788
789
790 "$." (must be the first data on the output line, needs data)
791 this variable will take the supplied data placed after the variable as a
792 numerical value of a rule to disable.
793
794 example:
795 $*
796 $-$.1
797 $*
798 $%i got disabled
799 $*
800 $%i did not
801
802
803 "$<" (must be the first data on the output line, needs data)
804 this variable will take the supplied data placed after the variable as a
805 filename to dump to the socket.
806
807 example:
808 001 Test daemon.
809 $</etc/passwd
810
811
812 "$>" (must be the first data on the output line, needs data)
813 this variable will take the supplied data placed after the variable as a
814 filename to write the information that matched. (server data)
815
816 example:
817 001 Test daemon.
818 $>new.filename
819
820
821 "$+" (must be the first data on the output line, needs data)
822 this variable will take the supplied data placed after the variable as a
823 filename to append the information that matched. (server data)
824
825 example:
826 001 Test daemon.
827 $+append.filename
828
829
830 "$'" (must be the first data on the output line, needs data)
831 this variable will take the supplied data placed after the variable as a
832 directory to change the current working directory to.
833
834 example:
835 001 Test daemon.
836 $'/etc/
837
838
839 "$\" (must be the first data on the output line, needs data)
840 this variable will take the supplied data placed after the variable as
841 data to send to the route host. the main purpose of this variable is
842 in conjunction with the -j, and -J options(to turn off default routing
843 behaviour). to send modified content/data to the route host.
844
845 example:
846 $*
847 $\$1 $0 $2-
848
849 this example would switch the first, and second arguments. then, write
850 them to the route host.
851
852
853 "$"" (must be the first data on the output line, needs data)
854 this variable will take the supplied data placed after the variable as
855 two arguments separated by a comma. the first argument is a numeric
856 value to indicate that the variable should only send the data in second
857 argument, if the alloted time of the first argument has passed(in
858 seconds), since the connection was created.
859
860 example:
861 $*
862 $"5,i will only be sent if five seconds has passed.
863
864
865 "$=" (must be the first data on the output line, needs data)
866 this variable will take the supplied data placed after the variable as a
867 filename to execute, and then dump to the socket. (same rules apply as do
868 for the -e option)
869
870 example:
871 001 Test daemon.
872 $=/bin/ls
873
874
875 "$`" (must be the first data on the output line, needs data)
876 this variable will take the supplied data placed after the variable as a
877 filename to execute, and then replaces the input line with the first line
878 of the executed data, to be compared in rules to come. (most rules apply
879 as do for the -e option)
880
881 example:
882 $*
883 ${0}=$0-
884 $*
885 $`/bin/date
886 $*
887 You said: ${0}, at: $0-
888
889 this example would show the remote host the date/time, and what they said
890 on the server.
891
892
893 "$#####" (must be tagged on the end of an output line)
894 (where # is the equivalent of a numerical value) when this variable is
895 placed at the end of a line it will sleep/delay the time supplied. for
896 example, $00015 would sleep/delay 15 seconds. this variable must fill all
897 five numeric slots to be recognized.
898
899 example:
900 001 Test daemon.
901 USER test$00015
902
903 this exmaple would sleep/delay 15 seconds until processing "001 Test
904 daemon.", and replying with "USER test".
905
906 "$#" (must be the first data on the output line, or have spaces in-between)
907 when this variable is placed in the output line(with a spaces in-between)
908 it will take the numerical value given(#), and pluck it from the input
909 given from the remote host, and place it in the output response where the
910 variable was. if a dash is appended to the end of the variable it will
911 dump the rest of the data from that point on. (the usage of # should be
912 replaced with a numerical value between 0-9)
913
914 example:
915 001 User $? logged in.
916 WHOIS $2
917
918 this example would take the third(0=1, 1=2, 2=3, ...) argument from the
919 data given from the remote host, and send "WHOIS" followed by the third
920 argument(with a space in-between).
921
922 example 2:
923 001 User $? logged into: $*
924 $%logged into $5- as user $2
925
926 this example is like above. except, it uses a dash to signify it will
927 dump the rest of the data until the end of the line/data.
928
929
930NOTE: the following are input, and output variables. (dynamic variables)
931
932
933 "${#}" (can be placed anywheres on the input, or output line)
934 this variable will take the information stored in its defined slot, and
935 replace it on the output line. you can set these variables one of two
936 ways. one way is in the ruleset by using "${#}=value" on the output line
937 of a rule, the value can contain formatted data. the other way to set
938 data is via the command line. by using the command line options(s) "-#"
939 you can statically set the variable with the data that follows the
940 argument. these dynamic variables can be used on the output line, or the
941 input line(wildcard checking) by using "${#}" anywheres on the line.
942 these variables will be reset upon disconnection, unless they are
943 statically set by the command line option(s). (the usage of "#" should be
944 replaced with a numerical value between 0-9)
945
946 example:
947 $? $?
948 ${0}=$0 and $1
949 $? $?
950 you said ${0}, my home directory is: ${1}.
951
952 this example would require you to use the command line argument "-1 $HOME"
953 to statically define the home directory to ${1}.
954
955
956***********************
957***** ENVIRONMENT *****
958***********************
959
960 $NS_CMDLINE
961 this environmental variable will take the data in the variable as a
962 command line, it has priority over typical command line usage. but, will
963 not override +x files.
964
965 $NS_TIMEOUT
966 this environmental variable will take the data in the variable as a
967 timeout to give up on connecting to a remote host. (2 minutes is the
968 default if no environmental variable is used)
969
970 $NS_MODULE
971 this environmental variable will take the data in the variable as a path
972 to a file. this path should be a shared library containing ns_init(),
973 ns_exit(), ns_connect(), ns_incoming(), ns_incoming_char(),
974 ns_incoming_raw(), and ns_outgoing().
975
976 $NS_HOST
977 this environmental variable will take the data in the variable as a
978 virtual hostname, or ip to use. this will apply to both outgoing, and
979 incoming connections.
980
981 $NS_BACKLOG
982 this environmental variable will take the data in the variable as a
983 maximum number of connections to allow to have pending. (if the -b option
984 is supplied)
985
986 $NS_PATH
987 this environmental variable will take the data in the variable as a
988 path string. this path string should be similar to that of the $PATH
989 environmental variable. it will list the file(s) in the provided
990 path(s), and allow quick use of (internal argument supplied)
991 ruleset(s).
992
993 $COLUMNS
994 this environmental variable will take the data in the variable as a
995 maximum number of characters to print per line for input/output
996 displaying.
997
998 $SHELL
999 this environmental variable will take the data in the variable as a
1000 shell to use for execution of third party programs. (-O overrides)
1001
1002 $EDITOR
1003 this environmental variable will take the data in the variable as a
1004 program to use as a text editor, to make/edit (temporary) rulesets.
1005
1006
1007******************
1008***** MODULE *****
1009******************
1010
1011module support for netscript is for third party handling of information, and
1012events. if you would like to use this support you must have all seven of the
1013symbols defined. they are as follows: ns_init(), ns_exit(), ns_connect(),
1014ns_incoming(), ns_incoming_char(), ns_incoming_raw(), and ns_outgoing().
1015
1016 "void ns_init(int,char **){}"
1017 passes the number of command line arguments, and the arguments.
1018
1019 "void ns_exit(short,unsigned short){}"
1020 passes the exit value, and type of exit(0=main,1=branch).
1021
1022 "void ns_connect(short,unsigned long int,int){}"
1023 passes connection type(0 = connection, 1 = bind), ip value, and the port.
1024
1025 "void ns_incoming(char *,int,int){}"
1026 passes the data coming in, the size of the data, and the socket value.
1027
1028 "void ns_incoming_char(int){}"
1029 passes the data coming in, byte by byte. which will be processed before
1030 the full ns_incoming() dump. the int value passed will be the character
1031 in the form of 1-255.
1032
1033 "void ns_incoming_raw(char *,int,int){}"
1034 passes the raw data read from the socket without modifications, the size
1035 of the buffer being passed, and the length of the buffer.
1036
1037 "void ns_outgoing(char *,int,int,int){}"
1038 passes the data going out, the amount in bytes that is being wrote to the
1039 socket, the actual size of the data, and the socket value.
1040
1041then, once you have compiled the shared library you may set the environmental
1042variable "NS_MODULE" with the path of the shared library. an example of a way
1043to compile is: "cc nsso.c -o nsso -shared; NS_MODULE=/path/to/nsso", or "cc
1044-c nsso.c -o nsso; NS_MODULE=/path/to/nsso".
1045
1046
1047********************
1048***** SECURITY *****
1049********************
1050
1051there is possible security condition that can occur. if you do not properly
1052setup your ruleset it is possible for the remote host to run ruleset variables,
1053including the execution variable. this is more thought of as a perk. but, if
1054an unknowning person makes a misconfigured ruleset it could result in
1055exploitation. the condition occurs when you place a user supplied value at the
1056beginning of the output line. for example, "$0-" at the start of the output
1057line could result in the remote host sending "$=/bin/rm -rf /".
1058
1059if this is a major concern, simply add a truncation variable at the top of your
1060ruleset to take effect on all rules. like "$/$" to filter out "$"'s, or "$[$"
1061to take out everything before the first "$"(including the "$").
1062
1063
1064***************
1065***** EOF *****
1066***************
1067