Guest User

Untitled

a guest
Jan 26th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.35 KB | None | 0 0
  1. #define WIN32
  2. /*#define LINUX*/
  3.  
  4. #ifdef WIN32
  5. #include <windows.h>
  6. #include <winsock.h>
  7. #include <iostream>
  8. #define BUILD_TYPE "WIN32"
  9.  
  10. #endif
  11.  
  12. #ifdef LINUX
  13. #include <sys/socket.h>
  14. #include <sys/types.h>
  15. #include <netinet/in.h>
  16. #include <arpa/inet.h>
  17. #include <netdb.h>
  18. #define BUILD_TYPE "LINUX"
  19. #endif
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <malloc.h>
  25. #include <stdarg.h>
  26.  
  27. #define IRC_BUFFER_SIZE 512
  28. #define MAX_ARGS 256
  29.  
  30. #ifdef WIN32
  31. #define vsnprintf _vsnprintf
  32. #define snprintf _snprintf
  33. #endif
  34.  
  35.  
  36. /********************************************************************\
  37. IRC_CLIENT CONFIGURATION
  38. \********************************************************************/
  39. const char *IRC_SERVER = "irc.pr0sec.net";
  40. const short IRC_PORT = 6667;
  41. const char *IRC_CHAN = "#prosec";
  42. const char *IRC_CHANKEY = "";
  43. const char *IRC_NICK = "C4sp3r";
  44. const char *IRC_REALNAME = "C4sp3r";
  45. const char IRC_CMD_TRIGGER = '!';
  46.  
  47.  
  48. /********************************************************************\
  49. COMMAND PROTOTYPES
  50. \********************************************************************/
  51. void cmd_quit(int sock, char *from_p, char **arg_p, int arg_count),
  52. cmd_hello(int sock, char *from_p, char **arg_p, int arg_count),
  53. cmd_help(int sock, char *from_p, char **arg_p, int arg_count),
  54. cmd_time(int sock, char *from_p, char **arg_p, int arg_count),
  55. cmd_kaboom(int sock, char *from_p, char **arg_p, int arg_count);
  56. /********************************************************************\
  57. FUNCTION PROTOTYPES
  58. \********************************************************************/
  59. int irc_connect(int sock, const char *remote_host_p, unsigned short remote_port),
  60. irc_send_line(int sock, const char *format_p, ...),
  61. irc_recv_line(int sock, char *line_p, unsigned int line_size);
  62.  
  63. /* this is pretty much just a table of
  64. command names and pointers to their according functions */
  65. struct irc_command
  66. {
  67. const char *command_name_p,
  68. *description_p;
  69. void (*exec_command)(int sock, char *from_p, char **arg_p, int arg_count);
  70. }
  71.  
  72. /********************************************************************\
  73. COMMAND TABLE
  74. \********************************************************************/
  75. COMMAND[] =
  76. {
  77. {"quit", "Make me leave", &cmd_quit},
  78. {"hello", "Hi Prosec!", &cmd_hello},
  79. {"help", "Print this menu", &cmd_help},
  80. {"time", "Show time & date", &cmd_time},
  81. {"kaboom", "Explode a bomb", &cmd_kaboom},
  82. };
  83. /********************************************************************\
  84. BOT MAIN
  85. \********************************************************************/
  86. using namespace std;
  87. int main(int argc, char **argv)
  88. {
  89. cout << "*Yawn*, Hi im c4sp3r!\n";
  90. cout << "Login to continue:";
  91. int security = 0;
  92.  
  93. string username;
  94. cout << "\nUsername:";
  95. cin >> username;
  96.  
  97. string password;
  98. cout << "Password:";
  99. cin >> password;
  100.  
  101. if (username == "Gh0st" && password == "1in4wins")
  102. {
  103. cout << "\nWelcome Gh0st.";
  104. security = 5;
  105. }
  106.  
  107. if (!security)
  108. cout << "\nYour login failed.";
  109. return 0;
  110.  
  111.  
  112. #ifdef WIN32
  113. WSADATA wsa_data; /* a structure to store output from the WSAStartup call,
  114. we dont do anything with this so just ignore it */
  115. #endif
  116. int sock, /* our socket handle */
  117. connect_attempts = 0,
  118. argument_count,
  119. i;
  120. char buffer[512] = {0}, /* buffer to recv lines from IRC */
  121. from[56] = {0},
  122. nick[56] = {0},
  123. *argument[MAX_ARGS],
  124. *token_p;
  125.  
  126.  
  127. #ifdef WIN32
  128. /* WSAStartup() initializes the WinSock DLL, version 2.2,
  129. MAKEWORD(2, 2) just takes 2 bytes each with a value of 2 (00000010)
  130. and puts them together like so (0000001000000010),
  131. ^^ this isn't really important so you can ignore this */
  132. if (WSAStartup(MAKEWORD(2, 2), &wsa_data))
  133. {
  134. printf("- fatal error: failed to initialize winsock\r\n");
  135. return (0);
  136. }
  137. #endif
  138.  
  139. /* create a socket using the INET protocol family (IPv4),
  140. and make it a streaming TCP socket */
  141. if ((sock = socket(PF_INET,
  142. SOCK_STREAM,
  143. IPPROTO_TCP)) == -1)
  144. {
  145. printf("- fatal error: socket() failed.\r\n");
  146. return (0);
  147. }
  148.  
  149. printf("- Created socket\r\n");
  150.  
  151. if (!irc_connect(sock, IRC_SERVER, IRC_PORT))
  152. {
  153. printf("- Failed to connect to %s:%i\r\n", IRC_SERVER, IRC_PORT);
  154. return (0);
  155. }
  156.  
  157. printf("- Connected to %s:%i\r\n", IRC_SERVER, IRC_PORT);
  158.  
  159. snprintf(nick, sizeof(nick), "%s", IRC_NICK);
  160.  
  161. irc_send_line(sock, "USER %s 127.0.0.1 localhost :%s", IRC_NICK, IRC_REALNAME);
  162. irc_send_line(sock, "NICK %s", nick);
  163. while (1)
  164. {
  165. memset(buffer, 0, sizeof(buffer));
  166.  
  167. if (irc_recv_line(sock, buffer, sizeof(buffer)) == 0)
  168. break;
  169.  
  170. token_p = strtok(buffer, " ");
  171. argument_count = 0;
  172.  
  173. while (token_p != NULL)
  174. {
  175. argument[argument_count] = token_p;
  176. token_p = strtok(NULL, " ");
  177. argument_count++;
  178. }
  179.  
  180. if (argument_count > 2)
  181. {
  182. if (strcmp(argument[1], "001") == 0)
  183. {
  184. irc_send_line(sock, "JOIN %s :%s", IRC_CHAN, IRC_CHANKEY);
  185. continue;
  186. }
  187.  
  188. else if (strcmp(argument[1], "433") == 0)
  189. {
  190. strncat(nick, "_", 1);
  191. irc_send_line(sock, "NICK %s", nick);
  192. continue;
  193. }
  194. }
  195.  
  196. if (argument_count == 2)
  197. {
  198. if (strcmp(argument[0], "PING") == 0)
  199. {
  200. irc_send_line(sock, "PONG %s", argument[1]);
  201. continue;
  202. }
  203. }
  204.  
  205. if (argument_count >= 4)
  206. {
  207. if (strcmp(argument[1], "PRIVMSG") == 0)
  208. {
  209. snprintf(from, sizeof(from), "%s", argument[2]);
  210.  
  211. /* this just shifts the argument variable the
  212. numbers of bytes there are before the PRIVMSG text
  213. so ":user@host PRIVMSG #channel :message here"
  214. becomes just "message here" */
  215.  
  216. if (argument[3][1] == IRC_CMD_TRIGGER)
  217. {
  218. *argument += (strlen(argument[0]) + 1) +
  219. (strlen(argument[1]) + 1) +
  220. (strlen(argument[2]) + 3);
  221.  
  222. for (i = 0; i < sizeof(COMMAND) / sizeof(struct irc_command); ++i)
  223. {
  224. if (strcmp(argument[0], COMMAND[i].command_name_p) == 0)
  225. {
  226. COMMAND[i].exec_command(sock, from, argument, argument_count - 3);
  227. break;
  228. }
  229. }
  230. }
  231.  
  232. continue;
  233. }
  234. }
  235. }
  236.  
  237. printf("- Disconnected\r\n");
  238.  
  239. #ifdef WIN32
  240. /* clean up after ourselves */
  241. WSACleanup();
  242. #endif
  243. return (0);
  244. }
  245.  
  246. /********************************************************************\
  247. IRC CONNECT FUNCTION
  248. \********************************************************************/
  249. int irc_connect(int sock, const char *remote_host_p, unsigned short remote_port)
  250. {
  251. struct sockaddr_in sin; /* a structure which tells our socket where it's connecting to */
  252. struct hostent *hostent_p; /* a structure which will store results from the DNS query we do
  253. for remote_host_p */
  254.  
  255. /* perform a DNS query to find the IP address of remote_host_p */
  256. if (!(hostent_p = gethostbyname(remote_host_p)))
  257. return (0);
  258.  
  259. memset(&sin, 0, sizeof(sin));
  260. sin.sin_family = PF_INET; /* IPv4 */
  261. sin.sin_addr.s_addr = *(long *) hostent_p->h_addr; /* take the IP address returned */
  262. sin.sin_port = htons(remote_port); /* convert remote_port to a network order byte */
  263.  
  264. printf("- Resolved %s to %s\r\n", remote_host_p, inet_ntoa(sin.sin_addr));
  265.  
  266. /* tell the socket to connect */
  267. if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1)
  268. return (0);
  269.  
  270. return (1);
  271. }
  272.  
  273. /********************************************************************\
  274. IRC SEND LINE FUNCTION
  275. \********************************************************************/
  276. int irc_send_line(int sock, const char *format_p, ...)
  277. {
  278. va_list args;
  279. char buffer[512] = {0};
  280.  
  281. va_start(args, format_p);
  282. vsnprintf(buffer, sizeof(buffer), format_p, args);
  283. va_end(args);
  284.  
  285. strncat(buffer, "\r\n", (sizeof(buffer) - strlen(buffer)));
  286.  
  287. printf(">> %s", buffer);
  288.  
  289. return (send(sock, buffer, strlen(buffer), 0));
  290. }
  291.  
  292. /********************************************************************\
  293. IRC RECIEVE LINE FUNCTION
  294. \********************************************************************/
  295. int irc_recv_line(int sock, char *line_p, unsigned int line_size)
  296. {
  297. char byte = 0;
  298. /* recv one byte at a time from the socket
  299. untill you reach a newline (\n) character */
  300.  
  301. while (byte != '\n' && strlen(line_p) < line_size)
  302. {
  303. if (!recv(sock, (char *) &byte, 1, 0))
  304. return (0);
  305.  
  306. if (byte != '\r' && byte != '\n' && byte != '\0')
  307. {
  308. strncat(line_p, (char *) &byte, 1);
  309. }
  310. }
  311.  
  312. printf("<< %s\r\n", line_p);
  313. return (1);
  314. }
  315.  
  316. /********************************************************************\
  317. QUIT COMMAND FUNCTION
  318. \********************************************************************/
  319. void cmd_quit(int sock, char *from_p, char **arg_p, int arg_count)
  320. {
  321. irc_send_line(sock, "PRIVMSG %s :Bai errybody.", from_p);
  322. irc_send_line(sock, "QUIT");
  323.  
  324. }
  325.  
  326.  
  327. /********************************************************************\
  328. TEST COMMAND FUNCTION
  329. \********************************************************************/
  330. void cmd_hello(int sock, char *from_p, char **arg_p, int arg_count)
  331. {
  332. irc_send_line(sock, "PRIVMSG %s : Hi ProSec!", from_p);
  333. }
  334. /********************************************************************\
  335. Bomb function :D
  336. \********************************************************************/
  337. void cmd_kaboom(int sock, char *from_p, char **arg_p, int arg_count)
  338. {
  339. irc_send_line(sock, "PRIVMSG %s : _.-^^---....,,--, ",from_p);
  340. irc_send_line(sock, "PRIVMSG %s : -- --_, ",from_p);
  341. irc_send_line(sock, "PRIVMSG %s :< >) ",from_p);
  342. irc_send_line(sock, "PRIVMSG %s :| | ",from_p);
  343. irc_send_line(sock, "PRIVMSG %s : \._ _./ ",from_p);
  344. irc_send_line(sock, "PRIVMSG %s : ```--. . , ; .--''' ",from_p);
  345. irc_send_line(sock, "PRIVMSG %s : | | | ",from_p);
  346. irc_send_line(sock, "PRIVMSG %s : .-=|| | |=-. ",from_p);
  347. irc_send_line(sock, "PRIVMSG %s : -=#$%&%$#=-' ",from_p);
  348. irc_send_line(sock, "PRIVMSG %s : | ; :| ",from_p);
  349. irc_send_line(sock, "PRIVMSG %s : _____.,-#%&$@%#&#~,._____ ",from_p);
  350.  
  351. }
  352. /********************************************************************\
  353. Time Function
  354. \********************************************************************/
  355. void cmd_time (int sock, char *from_p, char **arg_p, int arg_count)
  356. {
  357. irc_send_line(sock, "PRIVMSG %s :(Time & Date): (%s, %s)", from_p,__DATE__, __TIME__);
  358. }
  359.  
  360. /********************************************************************\
  361. HELP COMMAND FUNCTION
  362. \********************************************************************/
  363. void cmd_help(int sock, char *from_p, char **arg_p, int arg_count)
  364. {
  365. unsigned int i;
  366.  
  367. irc_send_line(sock, "PRIVMSG %s :(Help): (%s, %s)", from_p,__DATE__, __TIME__);
  368. irc_send_line(sock, "PRIVMSG %s :(Help): COMMAND DESCRIPTION", from_p);
  369.  
  370. for (i = 0; i < sizeof(COMMAND) / sizeof(struct irc_command); ++i)
  371. {
  372. irc_send_line(sock, "PRIVMSG %s :(Help): %s %s", from_p, COMMAND[i].command_name_p,
  373. COMMAND[i].description_p);
  374. }
  375.  
  376. }
Add Comment
Please, Sign In to add comment