1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
|
Nessus 0.99.0 C Plugins API
Author : Renaud Deraison <deraison@nessus.org>
Overview
-----------------------------------------------------------------
The Nessus Security Scanner performs its security
checks by launching external pieces of code called 'plugins'.
One plugin is in charge of one security check against one
host.
There are, at this time, two languages to write security checks :
NASL (the Nessus Attack Scripting Language) and C.
NASL should be prefered as it makes plugins which are easily
portable and shareable. C plugins should be avoided, except when
NASL proves to not be powerful enough.
This document teaches you how to write a C Nessus plugin.
Once more : *** C Nessus plugins should be avoided, except when
it is not possible to write them in NASL ***
This document covers the following topics :
1. How to compile a C plugin
2. The plugins framework
2.1 The main .c file
2.2 The file includes.h
2.3 The file nessusraw.h
2.4 The plugin_init() function
2.5 The plugin_run() function
3. The Nessus library functions
3.1 plugin_init() related functions
3.1.1 plug_set_name()
3.1.2 plug_set_category()
3.1.3 plug_set_family()
3.1.4 plug_set_description()
3.1.5 plug_set_summary()
3.1.6 plug_set_copyright()
3.2 plugin additional functions
3.2.1 plug_set_timeout()
3.2.2 plug_set_dep()
3.2.3 add_plugin_preference()
3.2.4 get_plugin_preference()
3.3 target informations
3.3.1 plug_get_hostname()
3.3.2 plug_get_host_ip()
3.3.3 plug_get_host_open_port()
3.3.4 host_get_port_state()
3.4 network operations
3.4.1 open_sock_tcp()
3.4.2 recv_line()
3.4.3 ftp_log_in()
3.4.4 ftp_get_pasv_address()
3.4.5 is_cgi_installed()
3.4.6 ping_host()
3.4.7 tcp_ping_host()
3.4.8 tcp_timing()
3.5 plugins inter communication (PIIC)
3.5.1 Introduction
3.5.2 plug_set_key()
3.5.3 plug_get_key()
3.5.4 Standard keys
3.6 Reporting a problem to the Nessus server
3.6.1 post_hole()
3.6.2 post_info()
4. Interfacing a Nessus plugin with the libpcap library
4.1 Makefile changes
4.2 libpcap-related Nessus functions
4.2.1 routethrough()
4.2.2 get_datalink_size()
5. A sample plugin commented
1. How to compile a C plugin
-----------------------------------------------------------------
C plugins must be compiled into shared libraries
before they can be used by Nessus. Turning a C file into
a shared library is a painful process, which is not portable.
That is why nessus-0.99.0 comes with the utility 'nessus-build'
which will build a .c plugin and turn it into a .nes file.
Its usage is :
nessus-build input.c output.nes
This script will create the directory $TMP/nessus-build and
will copy there the libtool which is appropriate to your system,
as well as a generic Makefile. But you should not care anyway,
except if your plugin contains several .c files.
2. The plugins framework
-----------------------------------------------------------------
2.1 The main .c file
----------------------------------------------------------------
The main .c file will contain the two critical functions that
we will discuss right after this.
2.2 The file "includes.h"
----------------------------------------------------------------
The file "includes.h" contains all the includes necessary to
write a plugin.
2.3 The file "nessusraw.h"
----------------------------------------------------------------
nessusraw.h contains all the includes to define the structs
ip, tcphdr, udphdr and icmp (BSD style). If these structures
are not defined in the system includes, then it redefines
them.
You should include this file if your plugin plays with
raw sockets.
2.4 the plugin_init() function
----------------------------------------------------------------
Synopsis :
int plugin_init(struct arglist * desc);
Description :
This function is called by the server so that the plugin
declares who is it, what it performs and so on. It should be
declared by your plugin, and must contain calls to the
following functions :
plug_set_name() (3.1.1)
plug_set_category() (3.1.2)
plug_set_family() (3.1.3)
plug_set_description() (3.1.4)
plug_set_summary() (3.1.5)
plug_set_copyright() (3.1.6)
It may also contain some calls to the function
add_plugin_preference()
We will define all these functions in section 3.1
(except add_plugin_preference which will be defined in another
section)
This function should return 0. Also, no initialization must be made
during this function, since all the dynamically allocated variables
will be destroyed right after the plugin exits from plugin_init()
2.5 the plugin_run() function
----------------------------------------------------------------
Synopsis :
int plugin_run(struct arglist * desc);
Description :
This is the main plugin entry point. It may contain whatever you want.
3. The Nessus library functions
-----------------------------------------------------------------
3.0 Notes on the internationalization of Nessus
----------------------------------------------------------------
nessus-0.99.0 and newer support multilingual plugins. That is,
each plugin may contain descriptions in any language.
As a result of this, most of the functions have
a 'language' argument which will tell nessusd in which
language the data passed is.
Those functions can be called several times, with a
different 'language' argument each time.
The 'language' argument must be NULL for english (default),
or must contain the same name as in nessusd.conf.
("deutsch", "francais", and so on...)
The NULL language must be called LAST !
Here is an exemple :
plug_set_name(env, "Test FTP", "francais");
plug_set_name(env, "FTP check", NULL);
3.1 plugin_init() related functions
----------------------------------------------------------------
3.1.1 plug_set_name()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void plug_set_name(struct arglist * desc, const char * name,
const char * language);
Description :
This function tells the server the full name of the plugin. The
name may contain spaces.
The argument 'desc' is the argument which is given to the function
plugin_init().
This function must only be called during plugin_init().
See also explained here :
languages (3.0)
plugin_init(2.3)
3.1.2 plug_set_category
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void plug_set_category(struct arglist * desc, int category);
Description :
This function tells the server in which category the plugin is.
The argument 'category' must be one of the following :
ACT_GATHER_INFO : the plugin gathers informations about the
remote host. No harm is made
ACT_ATTACK : the plugin will attack the remote server and
may steal sensitive data. However, no harm
is made : the attacked services are still working
after the plugin has done its job.
ACT_DENIAL : the plugin performs a denial of service attack
against the remote host.
ACT_PASSIVE : the plugin will perform a passive attack.
ACT_SCANNER : the plugin is actually a port scanner
If a plugin is in one of the first three category, then it will be
subject to a timeout watchdog on the server side, so even if there
is an infinite loop in it, the plugin will not make the server hang.
The two other categories are not subject to a timeout watchdog, so
you should double check your code when writing one.
The argument 'desc' is the argument given as a parameter to the
plugin_init() function.
This function must only be called during the plugin_init() function.
See also explained here :
plugin_init(2.3)
3.1.3 plug_set_family
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void plug_set_family(struct arglist * desc,
const char * family,
const char * name);
Description :
This function tells the Nessus server the family of the plugin.
The family name should be one of the existing family name
("CGI abuses", "Sendmail", and so on...), but you are free to
create your own family ("Joe's factory plugins").
The argument 'family' contains the family name.
The argument 'desc' is the argument given as a parameter to
plugin_init().
This function must only be called during the plugin_init() function.
See also explained here :
languages(3.0)
plugin_init(2.3)
3.1.4 plug_set_description
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void plug_set_description(struct arglist * desc,
const char * description,
const char * language);
Description :
This function sends the complete description of what the plugin does
to the Nessus server, which will in turn send it to the Nessus client
which will display it to the end user. So, 'description' should contain
a full description of what the plugin does. The string may contain
new lines.
The argument 'desc' is the argument given as a parameter to
plugin_init().
This function must only be called during the plugin_init() function.
See also explained here :
languages(3.0)
plugin_init(2.3)
3.1.5 plug_set_summary
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void plug_set_summary(struct arglist * desc,
const char * summary,
const char * language);
Description :
This function sends a summary of what the plugin does to the Nessus
server, which will in turn send it to the Nessus client which will
display it as tooltips which shortly explains what the plugin does.
It should NOT contain newlines, and should be as short as possible.
The argument 'desc' is the argument given as a parameter to
plugin_init().
This function must only be called during the plugin_init() function.
See also explained here :
languages(3.0)
plugin_init(2.3)
3.1.6 plug_set_copyright
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void plug_set_copyright(struct arglist * desc,
const char * author,
const char * language);
Description :
This function tells to the Nessus server who made the plugin, so that
the Nessus client can show it.
The argument 'author' should contain your name
The argument 'desc' is the argument given as a parameter to
plugin_init().
This function must only be called during the plugin_init() function.
See also explained here :
languages(3.0)
plugin_init(2.3)
3.2 plugin additional functions
----------------------------------------------------------------
3.2.1 plug_set_timeout
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void plug_set_timeout(struct arglist * desc, int timeout);
Description :
When a plugin is one of ACT_GATHER_INFO, ACT_ATTACK or ACT_DENIAL,
the Nessus server sets up a watchdog which waits for PLUGIN_TIMEOUT
seconds before killing the plugin.
This function allows your plugin to extend or to reduce the time you
want your plugin to run.
'timeout' is the new timeout limit for the plugin, in seconds.
The argument 'desc' is the argument given as a parameter to
plugin_init().
This function must only be called during the plugin_init() function.
See also explained here :
plugin_init(2.3)
3.2.2 plug_set_dep
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void plug_set_dep(struct arglist * desc,
const char * dependencie);
Description :
This function tells the Nessus server that you want your plugin to
be launched AFTER the plugin 'dependencie'.
The argument 'dependencie' is the *file name* of the plugin you want to
be launched before (ie: 'portmap.nes').
This function is useful when you deal with plugins intercommunication.
The argument 'desc' is the argument given as a parameter to
plugin_init().
This function must only be called during the plugin_init() function.
Note :
. If a plugin has multiple dependencies, it may call this function
several times, because all the dependencies will be
stored
. circular dependencies are not handled, so be sure to test which
plugin depends on which.
See also explained here :
plugin_init(2.3)
3.2.3 add_plugin_preference
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void add_plugin_preference(struct arglist * desc,
const char * preference_name,
const char * type,
const char * default_value);
Description :
This function will tell to the Nessus server that the plugin
must ask something directly to the user. The Nessus server will
forward this request to the client which will draw a dialog box
regarding your plugin.
This does not mean interactive communication with the user, but
additional preferences that must be set by the client.
An application for this feature would be password cracking program
which would ask the location of a dictionary file to the user.
+ preference_name : is the name that will appear on the client side
for the preference (for instance : 'wordlist location')
+ type : is one of the following :
PREF_ENTRY
PREF_CHECKBOX
PREF_RADIO
+ default_value : depends of the value of 'type'.
This needs to be explained :
PREF_ENTRY : the client will create a field where the user
can enter data. This is what you will use
if you want the user to give you the location
of a file.
If this is the type you choose, then 'value' will
be the default value inserted in the text area.
PREF_CHECKBOX: the client will create a checkable box where
that the user will activate or deactivate.
This is mainly useful for boolean questions.
If this is the type you choose, then 'value' will
have to be either 'yes' (box checked) or 'no'
(box not checked)
PREF_RADIO : the client will create a set of radio buttons,
and the user will only select one value among
the multiple ones.
If this is the type you choose, then 'value' will
be a list of semicolumn-separated differents value.
ie : "low;medium;high"
Only one of these words will be returned to the
plugin via the get_plugin_preference() function.
The argument 'desc' is the argument given as a parameter to
plugin_init().
This function must only be called during the plugin_init() function.
Note :
You should use wise default values, because not all Nessus clients
pay attention to the plugins preferences.
This function has a different name from the other plugins-related
functions (plug_*). This is because of the implementation
of this function which modifies the Nessus server global
preferences, whereas the other plug_* functions only modify
the structure 'desc'.
See also explained here :
plugin_init(2.3)
get_plugin_preference(3.2.4)
3.2.4 get_plugin_preference
---------------------------------------------------------------
Synopsis :
#include <includes.h>
char * get_plugin_preference(struct arglist * desc,
const char * preference_name);
Description :
Returns the value that was entered by the user for
a preference defined via add_plugin_preference()
The argument 'preference_name' must be the exact same
name as the one used in add_plugin_preference()
The argument 'desc' is the argument given as a parameter to
plugin_run().
This function must only be called during the plugin_run() function,
or in one of the functions called by this function.
Note :
Not all Nessus clients pay attention to the plugins preferences,
to the value returned by get_plugin_preference() may be the
default value you declared in add_plugin_preference()
This function has a different name from the other plugins-related
functions (plug_*). This is because of the implementation
of this function which modifies the Nessus server global
preferences, whereas the other plug_* functions only modify
the structure 'desc'.
See also explained here :
plugin_init(2.3)
add_plugin_preference(3.2.3)
3.3 Target informations
----------------------------------------------------------------
3.3.1 plug_get_hostname()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
const char * plug_get_hostname(struct arglist * desc);
Description :
Returns the name of the host being attacked.
'desc' is the argument given as a parameter to the function
plugin_run().
See also explained here :
plug_get_host_ip(3.3.2)
3.3.2 plug_get_host_ip()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
struct in_addr * plug_get_host_ip(struct arglist * desc);
Description :
Returns a pointer to the IP of the host being attacked.
'desc' is the argument given as a parameter to the function
plugin_run().
See also explained here :
plug_get_hostname(3.3.1)
3.3.3 plug_get_host_open_port()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
unsigned int plug_get_host_open_port(struct arglist * desc);
Description :
Returns the number of a port which is opened on the remote host.
'desc' is the argument given as a parameter to the function
plugin_run()
Returns :
The first open port of the remote host
or 0 if there is no open port.
Notes :
This function really attempts to connect to the remote port,
so you don't need to double-check its results
3.3.4 host_get_port_state()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
int host_get_port_state(struct arglist * desc, unsigned int port);
Description :
Returns the status of the tcp port 'port'.
'desc' is the argument given as a parameter to the function
plugin_run().
Returns :
1 if the port is open
0 if the port is closed
Note :
You should pay an extreme attention to this function. In fact,
it relies on the port scan to determine whether a port is open
or not, and the port you are asking for may or may not be
in the scanned range of port.
If the server has not scanned the port, then it is said to be
open, so you should use this function as :
If host_get_port_state() = 0, then we know that the port is closed
If host_get_port_state() is NOT 0, then the port MAY be open, but
you should double-check this one.
3.4 network operations
----------------------------------------------------------------
3.4.1 open_sock_tcp()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
int open_sock_tcp(struct arglist * desc, unsigned int port);
Description :
This function opens a socket and establishes the connection to
the remote host port 'port'.
'desc' is the argument given as a parameter to the function
plugin_run().
Returns :
. -1 if an error occured
. a valid socket fd if no error occured
3.4.2 recv_line()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
void recv_line(int soc, char * buffer, size_t buffer_size);
Description :
This function reads the data which is waiting on the socket
'soc' until a newline ('\n') is encountered or until the
size of the data read is equals to buffer_size.
'buffer' : is a buffer which will contain the data read
'buffer_size' : is the size of 'buffer'
Note :
This function does not handle timeouts. So if there is no data
to read this function will hang.
If you do not know whether there is data waiting or not, use
select(2).
3.4.3 ftp_log_in()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
int ftp_log_in(int soc, char * username, char * password);
Description :
This function logs into the remote FTP server as 'username/password'.
'soc' : is a freshly open socket to the remote FTP port (21)
Returns :
. 1 if an error occured (could not log in)
. 0 if we could log in
Notes :
If you want to connect anonymously, 'username' should be
set to 'ftp' and password to 'joe@'
See also explained here :
open_sock_tcp(3.4.1)
ftp_get_pasv_address(3.4.3)
3.4.4 ftp_get_pasv_address()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
int ftp_get_pasv_address(int soc, struct sockaddr_in * sockaddr);
Description :
This function issues the 'PASV' command, parses the result and
stores it in 'sockaddr'.
'soc' : is a socket connected to a FTP server we log into.
This is useful to connect to the data stream of a FTP server.
Returns :
. 1 if an error occured
. 0 in case of success
See also explained here :
open_sock_tcp(3.4.1)
ftp_log_in(3.4.2)
3.4.5 is_cgi_installed()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
int is_cgi_installed(struct arglist * desc, const char* cgi_name);
Description :
This function determines whether the cgi 'cgi_name' is installed.
If cgi_name does not start with '/', then this function will
look in /cgi-bin/, or else it will assume that you give the
full path to the cgi.
'desc' is the argument given as a parameter to the function
plugin_run().
Note :
Only nessus-alpha2 and newer makes a distinction about
whether the cgi_name starts by a '/' or not.
The older versions check everything in /cgi-bin/
Returns :
. 0 if the cgi is not installed
. 1 if it is
3.4.6 ping_host()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
int ping_host(struct in_addr host);
Description :
This function sends an ICMP echo query to the remote host,
(several times in fact) and waits for an answer.
Returns :
1 if the host is alive (replied)
0 if it is not
Note :
Using this function is not a good idea since many host do not
reply to ICMP ECHO queries any more. You should use tcp_ping_host()
instead.
See also :
tcp_ping_host(3.4.7)
3.4.7 tcp_ping_host()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
#include <nessusraw.h>
int tcp_ping_host(struct in_addr host);
Description :
This function will send two TCP packets to the remote host :
one with the TH_SYN and TH_ACK flags set, and if the does not
reply, one with the TH_FIN flag set. If the remote host
replies to one of these packets, then it is alive.
This functions puts the interface between localhost and
the remote host in promisc. mode, so that if any traffic
coming from the remote host is intercepted before it answers
our TCP packets, they will be considered as alive.
Returns :
1 if the remote host is alive (replied or traffic coming from
it has been sniffed)
0 if it is not (no answer)
Note :
Your plugin must be linked against the libpcap-nessus to use
this function, as tcp_ping_host() is defined in it.
3.4.8 tcp_timing()
---------------------------------------------------------------
Synopsis :
#include <includes.h>
#include <nessusraw.h>
long tcp_timing(struct in_addr host, int num_probes, int port);
Description :
This function returns the average TCP response time of the remote
host when sending SYN packets to the port <port>.
This function is mainly used to determine whether the CPU of
the remote host has jumped to 100% or not (you mesure the
variation of the response time between before and after an
attack).
Returns :
-1 if an error occured
0 if the host is the local host
The average reponse time, in ms, of the remote host
Notes :
You must link your plugin against the libpcap-nessus to use
this function.
This function will wait for each answer during 800 ms, no more.
3.5 plugins inter communication (PIIC)
----------------------------------------------------------------
3.5.1 Introduction
--------------------------------------------------------------
There is some need for the plugins to share their results. For instance,
the 'portmap.nes' plugin will check wether portmap is installed, and
some other plugins will be able to perform portmap-related functions
because they know that portmap is installed.
This avoids the redundancy of test, speeds up on the overall, and
make the attacks smarter.
Currently, the communication is done via 'keys' : you give the key
a name, and another plugin can call it.
The keys are only shared between the plugins that are attacking
the same host.
3.5.2 plug_set_key()
--------------------------------------------------------------
Synopsis :
void plug_set_key(struct arglist * desc,
char * name,
int type,
void * value);
Description :
Creates a new key which can be accessed by other plugins attacking
the same host.
'desc' is the argument given as a parameter to the function
plugin_run().
'name' is the name you will give to your key.
Currently, the names have the syntax :
service/name
(like : 'nis/domain')
But the function doesn't regard this kind of thing, so you are
allowed to call it whatever you want (the name must not include
a newline though)
'type' must be set to ARG_STRING which is the only data
format which is currently working. This is being worked on
though.
'value' is the data you want to set (typically, a pointer to a string)
It must not contain newlines.
Notes :
. This function will be modified soon to accept other data formats
and to accept that strings may contain newlines.
. strlen(name) + strlen(value) must be less than 500 chars
. When you call plug_get_key(), you send a message to
the nessus server which will send it in turn to the other
plugins when they are being launched. So, if you call
plug_set_key(..., "foo", ....) and then plug_get_key(...., "foo"),
plug_get_key() will not return the value you defined with
plug_set_key()
3.5.3 plug_get_key()
--------------------------------------------------------------
Synopsis :
void * plug_set_key(struct arglist * desc,
char * name);
Description :
Returns the value of the key 'name'.
Returns NULL if the key was not defined or was set to 0
3.5.4 Standard keys
--------------------------------------------------------------
Several plugins define the following keys. Note that you
must call plug_set_dep() if you want to use them, because
if you do not, your plugin may be launched before the plugin
which will set the key you are interested in.
Key : "OperatingSystem"
Defined in : "queso.nes"
Type : ARG_STRING
Value : name of the remote operating system
Key : "OperatingSystemVersion"
Defined in : "queso.nes"
Type : ARG_STRING
Value : version of the remote OS
Key : "ftp/anonymous_access"
Defined in : "ftp_anonymous.nes"
Type : ARG_STRING
Value : "yes" if the remote FTP server accepts anonymous
logins, "no" if it does not
Key : "ftp/writeable_dir"
Defined in : "ftp_write_dirs.nes"
Type : ARG_STRING
Value : NULL if there is no anonymous-writeable directory
or the name of a writeable directory on the remote
side.
Key : "ftp/writeable_root"
Defined in : "ftp_root.nes"
Type : ARG_INT
Value : 1 if the remote root directory is writeable when
logged in anonymously
Key : "rpc/portmapper"
Defined in : "portmap.nes"
Type : ARG_STRING
Value : "yes" if the remote host has an accessible portmapper
"no" if it does not
Key : "Services/ftp"
Defined in : "find_service.nes"
Type : ARG_INT
Value : The number of the port on which a FTP server is listenning
(not always 21). Set as an integer
Key : "Services/www"
Defined in : "find_service.nes"
Type : ARG_INT
Value : The number of the port on which a HTTP server is listenning
(not always 80). Set as an integer
Key : "Services/ssh"
Defined in : "find_service.nes"
Type : ARG_INT
Value : The number of the port on which a SSH server is listenning
(not always 22). Set as an integer
Key : "Services/smtp"
Defined in : "find_service.nes"
Type : ARG_INT
Value : The number of the port on which a SMTP server is listenning
(not always 25). Set as an integer
Key : "Services/http_proxy"
Defined in : "find_service.nes"
Type : ARG_INT
Value : The number of the port on which a HTTP proxy server is
listenning (not always 3128). Set as an integer
Key : "Services/pop2"
Defined in : "find_service.nes"
Type : ARG_INT
Value : The number of the port on which a POP2 server is
listenning (not always 109). Set as an integer
Key : "Services/pop3"
Defined in : "find_service.nes"
Type : ARG_INT
Value : The number of the port on which a POP3 server is
listenning (not always 110). Set as an integer
3.6 Reporting a problem to the Nessus server
---------------------------------------------------------------
3.6.1 post_hole()
--------------------------------------------------------------
Synopsis :
void post_hole(struct arglist * desc, int port,
const char * problem);
void post_hole_udp(struct arglist * desc, int port,
const char * problem);
void proto_post_hole(struct arglist * desc, int port,
const char * protocol,
const char * problem);
Description :
Sends to the Nessus server the description of a very serious
hole.
'desc' is the argument given as a parameter to the function
plugin_run()
'port' is the number of the port affected by the problem.
-1 means : 'general' and is used when the problem does not
come directly from a given port.
'protocol' is the protocol affected by the flow (ie: "tcp",
"udp", "icmp")
'problem' is the description of the problem, which may contain
newlines.
Notes :
post_hole() is used for TCP related holes
post_hole() and post_hole_udp() call the function proto_post_hole
If 'problem' is set to NULL, then this function will
return the description of the plugin, as registered in
plug_set_description(), in the user selected language.
See also explained here :
post_info(3.6.2)
3.6.2 post_info()
--------------------------------------------------------------
Synopsis :
void post_info(struct arglist * desc, int port,
const char * problem);
void post_info_udp(struct arglist * desc, int port,
const char * problem);
void proto_post_info(struct arglist * desc, int port,
const char * protocol,
const char * problem);
Description :
Sends to the Nessus server a warning regarding a service,
or a whole protocol.
'desc' is the argument given as a parameter to the function
plugin_run()
'port' is the number of the port affected by the problem.
-1 means : 'general' and is used when the problem does not
come directly from a given port.
'protocol' is the protocol affected by the flow (ie: "tcp",
"udp", "icmp")
'problem' is the description of the problem, which may contain
newlines.
Notes :
post_info() is used for TCP related warnings
post_info() and post_info_udp() call the function proto_post_info
If 'problem' is set to NULL, then this function will
return the description of the plugin, as registered in
plug_set_description(), in the user selected language.
See also explained here :
post_hole(3.6.1)
4. Interfacing a Nessus plugin with the libpcap library
-----------------------------------------------------------------
4.1 Makefile changes
---------------------------------------------------------------
Nessus now includes the libpcap, which is compiled as a shared
library called 'libpcap-nessus'. If your plugin needs the libpcap,
then its Makefile must be modified :
the line :
LIBS=-L${rootdir}/libs -lnessus
should become :
LIBS=-L${rootdir}/libs -lnessus -lpcap-nessus
Also, your plugin must make the following include :
#include <pcap.h>
See the libpcap documentation to learn how to use the libpcap.
4.2 libpcap-related Nessus functions
---------------------------------------------------------------
4.2.1 routethrough()
-------------------------------------------------------------
Synopsis :
char * routethrough(struct in_addr * dest,
struct in_addr * src);
Description :
This function returns the name of the interface (eth0, lo0, ...)
which will be used to reach the address "dest" going from the
address "src" (which is typically the local host IP).
Returns :
The name of the interface
or
NULL if an error occured
History :
This function was taken from Fyodor's Nmap, available at
http://www.insecure.org/nmap/
4.2.2 get_datalink_size()
-----------------------------------------------------------------
Synopsis :
int get_datalink_size(int datalink);
Description :
Returns the size of the data link of the interface.
datalink is the value returned by pcap_datalink()
5. A sample plugin commented
-----------------------------------------------------------------
Here is a typical Nessus plugin, which is pretty stupid.
Here is what it does :
- it makes sure it is run AFTER the plugin portmap.nes
- it asks the user whether it should run twice
- it checks whether the remote port 21 is open
- it attempts to connect anonymously on the remote
FTP server
- if it succeeds, then it reports that the remote FTP
server accepts anonymous connections
- it sets a PIIC key indicating whether the remote FTP
server accepts anonymous connections, so that the other
plugins will not have to attempt to connect if it does not
accepts anonymous connections
#include <includes.h> /* include all what we want */
/*
* Since the plugin name, description and so on
* may take some lines, I like to define them in the plugin
* header
*
* This will make
#define FR_NAME "plugin d'exemple"
#define NAME "sample plugin"
#define FR_DESCRIPTION "Ce plugin ne fait rien de\n\
spcial, il montre seulement comment crire un plugin"
#define DESCRIPTION "This plugin does nothing\n\
special, it justs shows how to write a plugin\n"
#define SUMMARY "does nothing"
#define FR_SUMMARY "ne fait rien"
#define COPYRIGHT "Renaud Deraison"
int
plugin_init(desc)
struct arglist * desc;
{
/*
* Required calls
*/
plug_set_name(desc, FR_NAME, "francais");
plug_set_name(desc, NAME, NULL);
plug_set_description(desc, FR_DESCRIPTION, "francais");
plug_set_description(desc, DESCRIPTION,NULL);
plug_set_summary(desc, FR_SUMMARY, "francais");
plug_set_summary(desc, SUMMARY, NULL);
plug_set_copyright(desc, COPYRIGHT,NULL);
plug_set_family(desc, "Test", NULL);
plug_set_category(desc, ACT_GATHER_INFO);
/*
* We want to be launched after portmap.nes
*/
plug_set_dep(desc, "portmap.nes");
/*
* And after queso.nes
*/
plug_set_dep(desc, "queso.nes");
/*
* We ask the user something
*/
add_plugin_preference(desc, "Run twice", PREF_CHECKBOX, "yes");
return(0);
}
int
plugin_run(desc)
struct arglist * desc;
{
/*
* This our plugin main entry point
*/
char * run_twice = get_plugin_preference(desc, "Run twice");
int soc;
int max = 1;
int i;
if(!strcmp(run_twice, "yes"))max++;
/*
* Do our stuff
*
* This plugin will just open a FTP connection to the remote host
*
*/
for(i=0;i<max;i++)
{
if(!host_get_port_state(desc, 21))return(0);
soc = open_sock_tcp(desc, 21);
if(soc < 0)return(0);
if(ftp_log_in(desc, "ftp", "joe@"))
{
/*
* The FTP accepts anonymous connections. We set
* it as a PIIC key
*/
plug_set_key(desc, "ftp/anonymous_open", ARG_STRING, "yes");
/*
* Warn that the FTP accepts anonymous connections
*/
post_info(desc, 21, "The remote ftp server\n\
accepts anonymous logins");
}
else plug_set_key(desc, "ftp/anonymous_open", ARG_STRING, "no");
}
return(0);
}
|