"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/ec_fingerprint.c" between
ettercap-0.8.3.tar.gz and ettercap-0.8.3.1.tar.gz

About: ettercap is a multipurpose sniffer/interceptor/logger for switched LAN.

ec_fingerprint.c  (ettercap-0.8.3):ec_fingerprint.c  (ettercap-0.8.3.1)
skipping to change at line 26 skipping to change at line 26
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include <ec.h> #include <ec.h>
#include <ec_file.h> #include <ec_file.h>
#include <ec_socket.h> #include <ec_socket.h>
#include <ec_fingerprint.h> #include <ec_fingerprint.h>
#ifdef HAVE_CURL
#include <curl/curl.h>
#endif
#define LOAD_ENTRY(p,h,v) do { \ #define LOAD_ENTRY(p,h,v) do { \
SAFE_CALLOC((p), 1, sizeof(struct entry)); \ SAFE_CALLOC((p), 1, sizeof(struct entry)); \
memcpy((p)->finger, h, FINGER_LEN); \ memcpy((p)->finger, h, FINGER_LEN); \
(p)->finger[FINGER_LEN] = '\0'; \ (p)->finger[FINGER_LEN] = '\0'; \
(p)->os = strdup (v); \ (p)->os = strdup (v); \
(p)->os[strlen(p->os)-1] = '\0'; \ (p)->os[strlen(p->os)-1] = '\0'; \
} while (0) } while (0)
/* globals */ /* globals */
skipping to change at line 188 skipping to change at line 191
strncpy(dst, l->os, OS_LEN+1); strncpy(dst, l->os, OS_LEN+1);
return -E_NOTFOUND; return -E_NOTFOUND;
} }
l = SLIST_NEXT(l, next); l = SLIST_NEXT(l, next);
} }
return -E_NOTFOUND; return -E_NOTFOUND;
} }
} }
if(EC_GBL_CONF->submit_fingerprint) if(EC_GBL_CONF->submit_fingerprint)
fingerprint_submit(f, "Unknown"); fingerprint_submit(NULL, NULL, f, "Unknown");
return -E_NOTFOUND; return -E_NOTFOUND;
} }
/* /*
* initialize the fingerprint string * initialize the fingerprint string
*/ */
void fingerprint_default(char *finger) void fingerprint_default(char *finger)
{ {
/* /*
skipping to change at line 292 skipping to change at line 295
} while ( i >>= 1 ); } while ( i >>= 1 );
if ( c == 1 ) if ( c == 1 )
return x; return x;
else else
return ( j ? j : 0xff ); return ( j ? j : 0xff );
} }
/* /*
* submit a fingerprint to the ettercap website * submit a fingerprint to the ettercap website
* Example of php code to intercept the post
<?php
$file = 'fingerprints.txt';
if( isset($_POST['finger']) && isset($_POST['os']) ) {
$fingerprint = 'finger is: ' . $_POST['finger'] . ' and os is: ' . $_POST['os
'] . PHP_EOL;
file_put_contents($file, $fingerprint, FILE_APPEND);
}
?>
*/ */
int fingerprint_submit(const char *finger, char *os) int fingerprint_submit(char* host, char* page, const char *finger, const char *o s)
{ {
int sock; char postparams[1024];
char host[] = "ettercap.sourceforge.net";
char page[] = "/fingerprint.php";
char getmsg[1024];
char *os_encoded; char *os_encoded;
size_t i, os_enclen; size_t i, os_enclen;
char fullpage [ PAGE_LEN + 1 ];
char fullurl[HOST_LEN + PAGE_LEN + 2];
#ifdef HAVE_CURL
CURL *curl;
CURLcode res;
#else
int sock;
#endif
if (strlen(host) == 0)
strcpy(host, DEFAULT_HOST);
if (strlen(page) == 0)
strcpy(page, DEFAULT_PAGE);
memset(getmsg, 0, sizeof(getmsg)); if (page[0] != '/')
strcpy(fullpage, "/");
strcat(fullpage, page);
strcpy(fullurl, host);
strcat(fullurl, fullpage);
memset(postparams, 0, sizeof(postparams));
/* some sanity checks */ /* some sanity checks */
if (strlen(finger) > FINGER_LEN || strlen(os) > OS_LEN) if (strlen(host) > HOST_LEN || strlen(fullpage) > PAGE_LEN || strlen(finger) > FINGER_LEN || strlen(os) > OS_LEN)
return -E_INVALID; return -E_INVALID;
USER_MSG("Connecting to http://%s...\n", host); os_encoded = strdup(os);
/* sanitize the os (encode the ' ' to '+') */
os_enclen = strlen(os_encoded);
for (i = 0; i < os_enclen; i++)
if (os_encoded[i] == ' ')
os_encoded[i] = '+';
USER_MSG("Submitting the fingerprint to %s...\n", fullurl);
#ifdef HAVE_CURL
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
snprintf(postparams, sizeof(postparams), "finger=%s&os=%s", finger, os_enc
oded);
SAFE_FREE(os_encoded);
curl_easy_setopt(curl, CURLOPT_URL, fullurl);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postparams);
res = curl_easy_perform(curl);
DEBUG_MSG("Post request content is: %s\n", postparams);
if (res != CURLE_OK) {
USER_MSG("Failed to submit fingerprint: %s\n", curl_easy_strerror(res))
;
} else {
USER_MSG("New fingerprint submitted to the remote website...\n");
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
#else
/* prepare the socket */ /* prepare the socket */
sock = open_socket(host, 80); sock = open_socket(host, 80);
switch(sock) { switch(sock) {
case -E_NOADDRESS: case -E_NOADDRESS:
FATAL_MSG("Cannot resolve %s", host); FATAL_MSG("Cannot resolve %s", host);
break; break;
case -E_FATAL: case -E_FATAL:
FATAL_MSG("Cannot create the socket"); FATAL_MSG("Cannot create the socket");
break; break;
case -E_TIMEOUT: case -E_TIMEOUT:
FATAL_MSG("Connect timeout to %s on port 80", host); FATAL_MSG("Connect timeout to %s on port 80", host);
break; break;
case -E_INVALID: case -E_INVALID:
FATAL_MSG("Error connecting to %s on port 80", host); FATAL_MSG("Error connecting to %s on port 80", host);
break; break;
} }
os_encoded = strdup(os);
/* sanitize the os (encode the ' ' to '+') */
os_enclen = strlen(os_encoded);
for (i = 0; i < os_enclen; i++)
if (os_encoded[i] == ' ')
os_encoded[i] = '+';
/* prepare the HTTP request */ /* prepare the HTTP request */
snprintf(getmsg, sizeof(getmsg), "POST %s?finger=%s&os=%s HTTP/1.1\r\n" snprintf(postparams, sizeof(postparams), "POST %s HTTP/1.1\r\n"
"Host: %s\r\n" "Host: %s\r\n"
"Accept: */*\r\n" "Accept: */*\r\n"
"User-Agent: %s (%s)\r\n" "User-Agent: %s (%s)\r\n"
"\r\n", page, finger, os_encoded, host, EC_ "Content-Length: %zu\r\n"
GBL_PROGRAM, EC_GBL_VERSION ); "Content-Type: application/x-www-form-urlen
coded \r\n\r\n"
"finger=%s&os=%s\r\n"
"\r\n", fullpage, host, EC_GBL_PROGRAM, EC_
GBL_VERSION, 7 + strlen(finger) + 4 + strlen(os_encoded), finger, os_encoded );
SAFE_FREE(os_encoded); SAFE_FREE(os_encoded);
USER_MSG("Submitting the fingerprint to %s...\n", page);
/* send the request to the server */ /* send the request to the server */
socket_send(sock, (const u_char*)getmsg, strlen(getmsg)); socket_send(sock, (const u_char*)postparams, strlen(postparams));
DEBUG_MSG("fingerprint_submit - SEND \n\n%s\n\n", getmsg);
/* ignore the server response */ /* ignore the server response */
close_socket(sock); close_socket(sock);
USER_MSG("New fingerprint submitted to the ettercap website...\n"); DEBUG_MSG("Post request content is: %s\n", postparams);
USER_MSG("New fingerprint submitted to the remote website...\n");
#endif
return E_SUCCESS; return E_SUCCESS;
} }
/* EOF */ /* EOF */
// vim:ts=3:expandtab // vim:ts=3:expandtab
 End of changes. 15 change blocks. 
25 lines changed or deleted 90 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)