| 0. 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. | /* * phelon.c * * Copyright (c) 2001 awnex <[email protected]> * * This is an IRC bot that I coded up a while ago. * It includes a debug option that prints out all incoming * and outgoing information. It's really useful when you * want to see who has been trying to access it without * your permission and to analyze all traffic. * * To use this bot you have to specify certain options. * phelon will read any message that you send it. Then it * will execute what it receives, aslong as you include CMD: * before you specify what you want it to execute. * If you want, you can change the CMD to anything * that you want. Just to prevent others from * accesing this program. I will be adding authentication * in the near future, so look out for the new phelon. * * This bot will execute the raw function of the command. * Here are a couple of examples on how to use the bot * once it is connected to an irc server: * * /msg bot CMD: join #channel * /msg bot CMD: join #channel channelkey * /msg bot CMD: mode #channel +s * /msg bot CMD: mode #channel +o yournick * /msg bot CMD: privmsg #channel uNF! * /msg bot CMD: privmsg yournick hi_sexy_bitch!!! * * When you want phelon to write a message to a channel, * or a specific nick, you have to use underscores in your * message. Otherwise it will only print out the first word, * and not the entire phrase. * * Here is an example on how to initialze phelon: * * % ./phelon -h * * [ phelon by awnex (c) 2001 ] * * usage: ./phelon <-n nick> <-c chan> [-k key] <-s server> [-d] * * As you can see the -d flag has no variable to use, that is because * once it is initialized it will print out all information that is being * sent to it. You can use phelon successfully without the -d flag if you want. * It is only there to debug the program while it is running. * * You do not have to use the -k flag for the key if you dont need to. * But if the chan that you want phelon to join does have a key you need to use * it. * * Shouts: Gersh (sexy BSD kernel hax0r) */ #include <stdio.h> #include <errno.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #define PORT 6667 #define BOTT "phelon" void usage (program) char *program; { fprintf (stdout, "\n[ phelon by awnex (c) 2001 ]\n"); fprintf (stdout, "\nusage: %s <-n nick> <-c chan> <-k key> <-s server> [-d] \n\n", program); exit(-1); } int main (argc, argv) int argc; char **argv; { struct hostent *he; struct sockaddr_in address; int x, opt, sockfd, debugging = 0; char *nick, *chan, *key, *ping, *server, *insert, *output; nick = chan = key = ping = server = NULL; insert = malloc(1024); output = malloc(1024); bzero (insert, 1024); bzero (output, 1024); while ((opt = getopt(argc, argv, "n:c:k:s:d")) != EOF) { switch (opt) { case 'n': nick = strdup(optarg); break; case 'c': { chan = strdup(optarg); if (*chan != '#' && *chan != '&') { fprintf (stderr, "Channel must be prefixed with '#' or '&'\ n"); exit (-1); } } break; case 'k': key = strdup(optarg); break; case 's': server = strdup(optarg); break; case 'd': debugging = 1; break; default: usage (argv[0]); break; } } if (!server) { fprintf(stderr, "Need to specify a server\n"); exit (-1); } if (!nick) { fprintf(stderr, "Need to specify a nick\n"); exit (-1); } if ((he = gethostbyname (server)) == NULL) { herror ("hostname"); exit (-1); } if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0) { perror ("socket"); exit (-1); } address.sin_family = AF_INET; address.sin_port = htons (PORT); address.sin_addr = * ((struct in_addr *) he -> h_addr); bzero (& (address.sin_zero), 8); if (connect (sockfd, (struct sockaddr *) &address, sizeof(struct sockaddr)) < 0) { perror ("connect"); exit (-1); } /* * * Set phelons nick. * */ sleep (1); snprintf (output, 1024, "USER %s phelon phelon %s\n", nick, BOTT); if ((send(sockfd, output, strlen(output), 0)) < 0) { perror ("USER"); return (1); } snprintf (output, 1024, "NICK %s\n", nick); if ((send (sockfd, output, strlen(output), 0)) < 0) return (1); /* * * Check to see if we own the nick. * */ bzero (insert, 1024); recv (sockfd, insert, 1024, 0); insert [strlen(insert) + 1] = '\0'; if (strstr (insert, "ickname")) { fprintf (stderr, "nickname: already in use\n"); return (1); } /* * * Join the default channel. * */ sleep (1); snprintf (output, 1024, "JOIN %s %s\n", chan, key); if ((send (sockfd, output, strlen(output), 0)) < 0) { perror ("join"); return (1); } fprintf (stdout, "\n\n- phelons status -\n\n"); fprintf (stdout, "nick: %s\n", nick); fprintf (stdout, "chan: %s\n", chan); fprintf (stdout, "serv: %s\n\n", server); while (1) { bzero (insert, 1024); recv (sockfd, insert, 1024, 0); insert [strlen(insert) + 1] = '\0'; if (debugging) printf("%s\n", insert); if (strncmp(insert, "PING", 4) == 0) { bzero (output, 1024); snprintf (output, 1024, "PONG :%s\n", ping); if (debugging) printf("%s\n", output); send (sockfd, output, strlen(output), 0); } /* * * Read message and execute. * */ if (strstr(insert, "CMD")) { char *ptr1 = insert, *ptr2; while ((ptr2 = strsep(&ptr1, ":")) != NULL) { if (!strncmp(ptr2, "CMD", 3)) { snprintf(output, 1024, "%s\n", ptr1); send(sockfd, output, strlen(output), 0); } } } } } |