phpseclib 2.0.12 - SFTP login failed but no error - phpseclib

I've installed phpseclib 2.0.12 with composer. I am running PHP 7.0.30.
I cannot log into an SFTP site using:
require($_SERVER["DOCUMENT_ROOT"] . "/vendor/autoload.php");
use phpseclib\Net\SFTP;
define('NET_SFTP_LOGGING', SFTP::LOG_COMPLEX);
$sftp = new SFTP($ftp_server);
echo("<pre>");
if (!$sftp->login($ftp_user_name, $ftp_user_pass)) {
print_r($sftp->getSFTPErrors());
echo $sftp->getSFTPLog();
exit('Login Failed');
} else {
echo("login worked");
}
echo("</pre>");
The output is simply:
Array
(
)
Login Failed
Why is logging not displaying anything at all? How can I see what is failing here?

You should be doing define('NET_SSH2_LOGGING', SSH2::LOG_COMPLEX); and $sftp->getLog(); instead. NET_SFTP_LOGGING only enables logging at the SFTP layer, which is only established after you've successfully authenticated.
Similarily, I'd do print_r($sftp->getErrors()); instead of print_r($sftp->getSFTPErrors());.

In case it helps someone else, I encountered a related issue and the password had a backslash in it. We changed our variable to use single quote marks instead of double and authentication worked. I suspect somewhere it was being treated as escape character. Perhaps this will helps someone save a few hours troubleshooting.

Related

AWS Amplify federated google login work properly on browser but dont work on Android

The issues are when I am trying to run federated authentication with the help of amplify auth method on the browser it works fine, but when I try to run it on my mobile.
It throws error No user found when I try to use Auth.currentSession() but the same work on the browser.
tried to search about this type of issue but I found related to ionic-cordova-google-plugin not related to AWS Amplify Federated Login Issue.
Updating the question after closing the question with less debugging information without asking for any information.
This is issues raised in git hub with respect to my problem.
Issue No. 5351 amplify js it's still in open state.
https://github.com/aws-amplify/amplify-js/issues/5351
Another issue 3537 which is still in Open
These two issues has the same scenario like me, I hope its enough debugging information, if more required mention comment instead of closing without notification, it's bullying for a beginner not helping
I fixed the above problem by referring a comment or wrapped around fix.
Link that will take to that comment directly link to comment.
First read the above comment as it will give you overall idea of what exactly the issue is instead of directly jumping to the solution.
Once you read the comment you will be little unclear with respect to implementation as he has use capacitor and not every one are using capacitor.
In my implementation I ignore this part as I am not using capacitor.
App.addListener('appUrlOpen')
Now lets go to main step where we are fixing this issue, I am using deep links to redirect to my application
this.platform.ready().then(() => {
this.deeplinks
.route({
"/success.html": "success",
"/logout.html": "logout",
})
.subscribe(
(match: any) => {
const fragment = JSON.stringify(match).split('"fragment":"')[1];
// this link can be your any link based on your requirement,
// what I am doing it I am passing all the data which I get in my fragments.
// fragments consists of id_token, stage, code,response type.
// These need to be passed to Ionic in order for Amplify to run its magic.
document.location.href = `http://192.168.1.162:8100/#${fragment}`;
},
(nomatch) => {
console.log("Got a deeplink that didn't match", nomatch);
}
);
});
I got this idea by referring the issue in which the developer mentioned of sending code and state along with application deep linking URL.

TypeError: can only concatenate str (not "DeferredAttribute") to str

I am wondering anyone can help me in one of the thing I cannot get my around it and really bothering as I spent last two on it but couldnt make it.
Basically, I am building an App (Django Python) to restore the information regarding all the network device e.g hostname, IP Address, S/N, Rack info etc. but I also to enable few options like Add, Edit, Delete and Connect next to device entery. I was able to create all the options except Connect option where I am completely stuck, I am trying to query database to get the IP address information and then using Popen module to open a putty window with the ssh to that IP Address device related, I tried everything I could but nothing worked, thereofrore, asking your help if you have any idea about this ? or any other alternative method for a user when he click on connect the putty or similar app will open and he just put the login credentials and get into the device.
I am sharing my code here, let me know if I am doing something wrong.
on the show all device page, i have this code, show.html
<td>Connect</td>
<!--<td>Connect</td>-->
I tried both ways, with id and ip address entry in the database
on view.py
def connect(request, ip_address):
hostlist_ip = HostList.ip_address
print(hostlist_ip)
Popen("putty.exe" + hostlist_ip)
return redirect('/show')
and in the url.py
path('connect/<str:ip_address>', views.connect),
or
path('connect/<str:ip_address>', views.connect),
Since I am also printing the the output on the terminal I notice that it is not returning the actually IP address but return this;
<django.db.models.query_utils.DeferredAttribute object at 0x04B77C50>
and on the web I receiving this error
TypeError at /connect/10.10.32.10
can only concatenate str (not "DeferredAttribute") to str
Request Method: GET
Request URL: http://localhost:8000/connect/10.10.32.10
Django Version: 2.2.3
Exception Type: TypeError
Exception Value:
can only concatenate str (not "DeferredAttribute") to str
let me know if you can help.
Just a F.Y.I I already tested the Popen via python but since we not getting the actual IP address from the database I am seeing this and I am a complete newbie with html/css and Djano, however I have some basic knowledge of python, so please ignore my any stupid comments in the post.
Many thanks
ahh I cannot believe I spend two day to troubleshoot this and just changed the name from ip_address to ip_add and it is working now :) i think as I mentioned above in the comment, it probably confusing with the built in module
here is simple solution:
views.py
def connect(request, ip_add):
import os
from subprocess import Popen
Popen("powershell putty.exe " + ip_add)
return redirect('/show')
url.py
path('connect/<str:ip_add>', views.connect),
I may have to find out a way if user is using the mac or linux, how I am going to change this powershell to something else. but anyhow it is working for windows
thanks all for the responses.

Mod_security issue with DELETE and PUT request?

Hello everyone,
I build a simple API and everything is working fine on my localhost. When i placed it on my server i started getting this error when i try to do a PUT or DELETE request.
I looked up the NOYB thing and i found out that i have Mod_Security enabled and that this is causing the error. I tried switching this off for the domain but either i'm doing it wrong or this is not the problem.
I hope you guys can help me out real quick here since this needs to be working before the end of the night.
Any help is appreciated.
Although it is a bit late for your needs, here is an answer which may help others in your situation.
Fist create the tools needed to test the solution, assuming a configuration using PHP:
//server-side script test-put.php
< ?php
parse_str(file_get_contents('php://input'), $vars);
print_r($vars);
//client-side script send-put-req.php
< ?php
$result = file_get_contents(
'http://www.testsite.ro/test-put.php',
false,
stream_context_create(array(
'http' => array(
'method' => 'PUT'
)
))
);
print_r($result);
Then look into the error_log file (/usr/local/apache/logs/error_log) for the line of mod_security complaning every time a request comes from the script above. In my configuration I had to change this one (/usr/local/apache/conf/modsec2.user.conf):
# allow request methods
SecRule REQUEST_METHOD "!^((?:(?:POS|GE|PU)T|OPTIONS|HEAD**|DELETE))$" \
"phase:2,t:none,log,auditlog,status:501,msg:'Method is not allowed by policy', severity:'2',id:'960032',tag:'POLICY/METHOD_NOT_ALLOWED'"

Trying to communicate with a REST service with NSIS

All I am trying to do is send an HTTP GET with Querystring or HTTP POST to a web service from within a custom page in an NSIS installer.
The problem is that most plugins can upload/download files, but not simply call a service and return the response. The recommend plugin to use is NsisUrlLib. I tried this, and while it works with simple GET requests, it fails and throws an error if you have querystring parameters in the URL, such as:
NsisUrlLib::UrlOpen /NOUNLOAD "http://tc.hwidev.com?var=value"
Pop $connectResult
NSISdl,INetC, and other plugins work with querystrings but can only be used to upload/download files.
I tried using the ExecDos plugin to call cURL.exe from the command line like so:
ExecDos::exec /TOSTACK "curl" "http://tc.hwidev.com"
Pop $connectResult
But I can't figure out how to get the data returned from the URL passed back to NSIS. The above code just returns an integer into $connectResult which probably represents the return code from CURL. How do I get the actual HTML returned from the URL onto the NSIS stack or into a variable?
Alternatively, can anyone recommend a better way to accomplish this? Calling a webservice seems so basic that thousands of people should have already figured this out.
NSISdl, Inetc etc, aren't just for uploading/downloading files. I think you are misunderstanding this point. You can use them to call REST apis, but you'll need to save the answer to a local file, and then parse it.
Example: Calling to an REST api that answers XML:
# Call to REST API
NSISdl::download_quiet "http://remotesite?restparams" "$TEMP/result.xml"
# Parse answer
nsisXML::create
nsisXML::load "$TEMP/result.xml"
nsisXML::select "/response/status"
# Clean
delete "$TEMP/result.xml"
That's it.
NSISdl::download_quiet "http://127.0.0.1/vid.php?vid=1" "$TEMP/checkvid.txt"
FileOpen $0 $TEMP\checkvid.txt r
FileRead $0 $1
DetailPrint $1
FileClose $0
${If} $1 == "vidNTYE1203"
MessageBox MB_OK "video found"
Delete "$TEMP\checkvid.txt"
${Else}
MessageBox MB_OK "bye bye"
Delete "$TEMP\checkvid.txt"
Quit
${EndIf}
This is my work snippet for production.Working good,for me.Pay attention for 'Delete' command and '\' slash .
I would recommend INetC over NsisUrlLib, the older firefox installer used it with much success.

Getting Not Authorized error from twitcurl timelineUserGet method

I'm currently playing with C++ on Linux and Twitter using twitcurl. I've built twitcurl, and it seems to work generally, I've been able to tweet from a slightly customised version of the twitterClient sample from their project. However, I've been struggling to read user's timelines.
Now, I know general authentication is working as I manage to tweet as the correct user first.
However, when I try to read user timelines using the below code:
/* Get user timeline */
replyMsg = "";
printf( "\nGetting user timeline\n" );
if( twitterObj.timelineUserGet( true, false, 5 ) )
{
twitterObj.getLastWebResponse( replyMsg );
printf( "\ntwitterClient:: twitCurl::timelineUserGet web response:\n%s\n", replyMsg.c_str() );
}
else
{
twitterObj.getLastCurlError( replyMsg );
printf( "\ntwitterClient:: twitCurl::timelineUserGet error:\n%s\n", replyMsg.c_str() );
}
I get the following error:
twitterClient:: twitCurl::timelineUserGet web response:
<?xml version="1.0" encoding="UTF-8"?><hash><request>/1/statuses/user_timeline.xml? count=5?trim_user=1</request><error>Not authorized</error></hash>
I'm unsure whether this is related to the invalid url twitcurl generates with multiple ? symbols which might conflict with authentication.
The full source code can be found at https://github.com/paulspencerwilliams/CPlusPlusSocialPlayground/blob/master/twitterClient.cpp .
The following post helped me to solve the same problem
What steps will reproduce the problem?
Sending certain characters to twitter API (Any character that has to be percent encoding, except the blank space?).
What is the expected output? What do you see instead?
I'd expect
twitter's server to accept my oauth signature but it hits me in the
face instead.
What version of the product are you using? On what operating system?
r88, this problem applies to both linux and wii (through devkitpro)
Please provide any additional information below.
The problem can be fixed by removing the urlencode() calls within buildOAuthRawDataKeyValPairs() in oauth.cpp.
That is according to how twitter says we have to do it. I don't know (did not check) if that's how the oauth spec says it should be done but it is clearly how it works with twitter.
Did you write oauthlib.cpp?