Connect to SUSE using libssh - c++

I am trying to establish a connection using libssh(https://www.libssh.org/) to a machine with SUSE Enterprise operating system installed.
ssh_options_set(tempSshSession, SSH_OPTIONS_HOST, host2Connect);
ssh_options_set(tempSshSession, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(tempSshSession, SSH_OPTIONS_PORT, &port);
int rc = ssh_connect(tempSshSession);
if(rc != SSH_OK) {
printf("Error connecting to the localhost\n");
exit(-1);
}
// Authorized by the password.
rc = ssh_userauth_password(tempSshSession, username, password);
After ssh_userauth_password() call it returns the response : "SSH_AUTH_DENIED: Authentication failed: use another method"
It works fine for operating systems like: Ubuntu, Linux Generic and CentOS.
Thanks

Check /etc/ssh/sshd_config. You should find PermitRootLogin forced-command-only somewhere there. Set that to yes and your problem should be gone. Please keep in mind that there is a reason, why folks have decided to not allow per default root user/pass logins.

Related

Sniffing raw sockets (SOCK_RAW) without Administrator account in windows

I am creating a simple sniffer using c++ under visual studio , and windows 10 x64 , but when I tried to run it. I got Failed to create raw socket. which is because admin rights , but I was reaching on internet . I could use something like CAP_NET_ADMIN , but it is linux based . is there a way to do under windows such as wireshark non-root users works?
//Initialise Winsock
printf("\nInitialising Winsock...");
if (WSAStartup(MAKEWORD(2,2), &wsa) != 0)
{
printf("WSAStartup() failed.\n");
return 1;
}
printf("Initialised");
//Create a RAW Socket
printf("\nCreating RAW Socket...");
sniffer = socket(AF_INET, SOCK_RAW, IPPROTO_IP);
if (sniffer == INVALID_SOCKET)
{
printf("Failed to create raw socket.\n");
return 1;
}
printf("Created.");
Creating a Raw Socket:
Raw sockets offer the capability to manipulate the underlying
transport, so they can be used for malicious purposes that pose a
security threat. Therefore, only members of the Administrators group
can create sockets of type SOCK_RAW on Windows 2000 and later.
If anyone is getting this with Wine, you need to allow the wineserver to use Ping.SendPrivileged:
sudo setcap CAP_NET_RAW=ep /usr/bin/wine
sudo setcap CAP_NET_RAW=ep /usr/bin/wineserver
sudo setcap CAP_NET_RAW=ep YOUREXE.exe

MySQL Api: Lost connection to MySQL server during query

There are zillions of these questions I know, but none of them were similar to my issue, so I figured I'd ask. I have a server set up that validates clients that connect to it by receiving username/password combinations and checking them using a SQL query. I wrote the system, and it worked perfectly fine during the first couple of requests.
http://puu.sh/d9mss/384b4df9f0.png
However, I found that if I wait about 5 minutes and then try to connect, this happens.
http://puu.sh/d9mx7/192cbb2cfc.png
This is the code that I am running to perform that task.
bool CNetDatabase::AuthUser(std::string username, const unsigned char* passwordhash)
{
RoughSanitizeString(username); //this doesn't do anything
/* Turn password hash into string */
std::ostringstream password;
password.fill('0');
password << std::hex;
for (int i = 0; i < 20; i++)
{
password << std::setw(2) << (unsigned int)passwordhash[i];
}
/* Make request */
MYSQL_RES* result = nullptr;
if (mysql_query(sql_con, tools::string::format(
"SELECT COUNT(`index`) FROM `Users` WHERE `username` = '%s' AND `password` = '%s'",
username.c_str(), password.str().c_str()).c_str()))
{
fprintf(
stderr,
"ERROR: mysql_query failed: %s [%d]\n",
mysql_error(sql_con), mysql_errno(sql_con));
return false;
}
/* Get and return result */
result = mysql_store_result(sql_con);
MYSQL_ROW row = mysql_fetch_row(result);
mysql_free_result(result);
return row[0][0] == '1' ? true : false;
}
Any ideas on what could be going wrong?
Check MySQL manual. There are session timeouts on both client and server side.
Anyway it is a good practice to expect that connection to external resources may become unavailable and try to reconnect (for instance database server could be physically rebooted). You can try to set reconnect flag when creating connection to enable automatic reconnects but those might not always work depending on your environment.
Upon further investigation, I think it's safe to conclude that it is my host's problem, not my code. I registered an account with a site that offered the ability to make free MySQL databases, and my server has been throwing SQL queries at it without issue all night. For posterity, if you are using your website's SQL server and are hosting with Hostgator, they might be causing the issue.

Bluetooth with C++ and winsock

I'm finding it very hard to get information on Bluetooth communication in C++. Specifically I want to avoid using any third party libraries and I simply want to connect to a device already paired with my computer.
The device has already had its passcode entered and is available in the 'Show Bluetooth Devices' under my devices and printers. I'm using Windows 7 and visual studio 2013 professional for development in C++.
I've got some example code (from here http://www.winsocketdotnetworkprogramming.com/winsock2programming/winsock2advancedotherprotocol4k.html) which displays information on my Bluetooth radio and then displays device information and it seems to work well. Although it's printing out every Bluetooth device already paired with the computer, not ones which are within range, but that may be me misinterpreting what the code is suppose to do.
I've been looking through the Bluetooth reference page (http://msdn.microsoft.com/en-us/library/windows/desktop/aa362930%28v=vs.85%29.aspx) and all the functions are just to do with setting the Bluetooth radio availability and other things like that; no sign of connecting to a found device at all.
I must be missing something, using wrong key words when Googling or something, because I've found nothing about connecting to a Bluetooth device!
If anyone has any suggestions, code, or links that would be great! I can connect to my device using the serial functionality (very easily) but I have to manually enter the COM port it's registered on, which isn't very user friendly. I want to scan and select, or enter a Bluetooth device name, and connect that way.
Cheers
EDIT:
BitBanks answer pointed me in the right direction. Only thing missing was a WSAStartup request before any socket requests:
WORD wVersionRequested;
WSADATA wsaData;
int err;
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
/* Tell the user that we could not find a usable */
/* Winsock DLL. */
printf("WSAStartup failed with error: %d\n", err);
return 1;
}
If you have a bluetooth address from discovery or the paired-devices list, you can connect to it like this (error checking needs to be added):
#include <winsock2.h>
#include <ws2bth.h>
SOCKADDR_BTH sockAddr;
SOCKET btSocket;
int error;
btSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
memset (&sockAddr, 0, sizeof(sockAddr));
sockAddr.addressFamily = AF_BTH;
sockAddr.serviceClassId = RFCOMM_PROTOCOL_UUID;
sockAddr.port = BT_PORT_ANY;
sockAddr.btAddr = <your bluetooth address>
error = connect(btSocket, (SOCKADDR*)&sockAddr, sizeof(sockAddr));
Some devices advertise the SerialPortServiceClass_UUID instead of the RFCOMM_PROTOCOL_UUID. You also may need to retry the connection several times. Certain poorly implemented bluetooth devices (cough PowerA Moga cough) require multiple tries to connect.
This may not be the official way to do it, but I get the 6-byte BT address of the device I'm interested in from the paired list like this:
unsigned char *p;
ULONGLONG ullAddr;
p = (unsigned char *)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr; // point to addr
memcpy(&ullAddr, &p[2], 8); // copy Bluetooth address of device we found

Visual C++ ODBC application cannot connect to MySQL database

I'm writing my first database application following a sample program the teacher given, but neither the sample, nor my own program can't connect to the database. (The JDBC sample program can, so the server should be OK).
I have these vars in the class declaration:
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLRETURN ret;
Here's the constructor of my database handler class, that's where the connection should be made:
DBModule::DBModule(string server, string database)
{
this->server = server; //"localhost" is loaded into it
this->database = database; //"test" is loaded into it, of course it exists on the server
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
command = "DRIVER={MySQL ODBC 3.51 Driver};SERVER="+this->server+";DATABASE="+this->database+";";
//command looks like this now:
//"DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;"
ret = SQLDriverConnect(dbc, NULL, (SQLWCHAR *)command.c_str(), SQL_NTS, NULL, 0, NULL, SQL_DRIVER_COMPLETE);
if (!SQL_SUCCEEDED(ret)) {
err += CONNECT_DATABASE*DATABASE_UNREACHABLE;
good = false;
return;
} else {
good = true;
}
SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
command = sysToStd(DBINIT);
SQLPrepare(stmt, (SQLWCHAR *)command.c_str(), SQL_NTS);
ret = SQLExecute(stmt);
}
The ret at SQLDriverConnect gets a -1 value.
I'm using the latest XAMPP as server with all the default settings (so i'm "root" and there is no password). I've tried adding UID=root to the connection string, but it did the same.
Thanks for any help.
You probably do not have MySQL ODBC drivers installed. JDBC works because you need not "install" them: they are some .jar files that can come with Java application. If you will use ODBC then install MySQL ODBC drivers, configure connection in ODBC Manager as System DSN, then from ODBC manager check if it connects to database (most ODBC drivers I know have "test connection" button).
When such test shows you "connected" or similar, then you can test if your application connects. Your connect sting looks like:
DRIVER={MySQL ODBC 3.51 Driver};SERVER=...;DATABASE....
so according to: http://www.connectionstrings.com/mysql#p30 it looks you are trying to use MySQL Connector/ODBC 3.51
Maybe database is not listening on dafult port?

sendto fails with a non administrator user with errorcode 10013

I found more source codes which are working like ping. My only problem with them is, that if i run the program with a non administrative user, then i get back errorcode 10013 which means : "An attempt was made to access a socket in a way forbidden by its access permissions." If i run the program with a user which is member of the administrator goup then it's working fine.
nResult = sendto (sock, pSendBuffer, sizeof (ICMPheader) + nMessageSize, 0, (SOCKADDR *)&dest, sizeof (SOCKADDR_IN));
::GetSystemTime (&timeSend);
++nPacketsSent;
if (nResult == SOCKET_ERROR)
{
cerr << endl << "An error occured in sendto operation: " << "WSAGetLastError () = " << WSAGetLastError () << endl;
}
Can anyone help me to solve this problem, or tell me why can't a non administrator user use this code? If not, then i would appriciate some code, which i can use with a user which isn't member of the administrator group.
Thanks in advance!
kampi
If you want to implement ping functionality in your application on Windows, then you should have a look at the IcmpSendEcho2 function instead of trying to use raw sockets.
Is your socket of type SOCK_RAW? In that case this is by design:
RAW Socket Access Denied to Non-Admin Windows NT 4.0 and Windows 2000 Users
by any chance, is your code using a raw socket ? if this code really implements a PING request, then it should be using raw sockets.
due to security considerations (people that considered those considerations did not consider much, but that's for another post), raw sockets are only available for accounts which have administrator privileges.