test windows rdp credentials use and password - php

I want to make an checker to check RDP IP with user and password
I've tried to install guacamole server I install it on ubuntu and it works good and connects well but I can't make any check using php or any coding language with it because its system is so complicated
so if any one have any idea about how to check RDP IP with user and password using any coding please let me know

You can use command line RDP clients (or this one) for linux if you environment is a Linux (or MacOS), or run RDP client from command line if you using Windows.
guacamole is not good idea for automation. You need to run web-side javascript to connect, so Selenium or Chrome headless will be only possible solution as I know.
EDIT 1: How to run remote command
Set SSH passwordless connection to freerdp server
Run freerdp command on remote server via SSH connection
$process = new Process(['ssh', 'user#serverB' 'freerdp ...']);
$process->run();
In other way you can create standalone PHP service on serverB which trying to run local freerdp command with requested IP (or user?) and returning result

Related

How to initialize a PHP websocket service in CPanel/External web host?

I have developed a web app which shows information in real time from certain actions carried out by different users. For this I use websockets, built in PHP, in a local environment (WAMP) and works fine, but I need this to also work on an external server (web hosting service), which I only have access to through the CPanel and FTP.
Locally I make the websocket work executing next code line through Windows' CMD:
C:\wamp64\bin\php\php7.2.10\php.exe -q C:\wamp64\www\myapp\websocket_daemon.php
My question is, how can I achieve the same result in CPanel, or maybe there is another way?
It is not likely for a shared hosting environment (i.e. Apache with VirtualHost config, PHP, MySQL, and a CPanel interface) to support your websocket application.
For websocket to work, you need to either:
have a port dedicated to websocket in-bound connections; or
have a HTTP/HTTPS server that knows when to upgrade a connection and proxy pass to your websocket application.
To run your own websocket service, you should think about using Virtual Private Server services such as Amazon EC2, DigitalOcean VPS.
For that purpose you will need to have CLI (Command-Line Interface) access to the (Linux) server involved. Assuming that you have such access, running the WS service would look something like
./websocket_daemon.php
The small script assumes that you are in the appropriate folder. However, you need to resolve a few things before you get there:
Step 1: SSH support on your machine
You will need to ensure that your OS supports SSH. Your OS appears to be Windows, so you will need to either install Putty of Git Bash. Read about these technologies
Step 2 Generate an SSH key
In your CPanel, you will need to generate SSH keys:
Click on Manage SSH Keys
Click on Generate a New Key
Use the settings you prefer in order to generate a key, don't worry, you can remove the SSH keys at any time and recreate them if you realize that you prefer a different way to generate them
Read more here: https://docs.cpanel.net/cpanel/security/ssh-access/
SSH keys are composite keys, that is, it consists of a private and a public key. You can share your public key with anyone, but never ever send your private key to anyone. It should be on your computer and possibly saved to backups. Read more about SSH keys here: https://sectigo.com/resource-library/what-is-an-ssh-key
Step 3: Ensure that your computer uses the SSH keys you have generated for CPanel
You will need to tell your OS where the SSH key-pair is located, luckily this is not a new problem, see an exhausting discussion about this topic here: https://serverfault.com/questions/194567/how-do-i-tell-git-for-windows-where-to-find-my-private-rsa-key
Step 4: Test your SSH
Run the following command into your CLI that supports SSH:
ssh <username>#path
If there is no error, then you have successfully tested SSH and you are almost ready to proceed further
Step 5: Upload your Websocket script
You can do this via FTP, as you already know, but you can also do it via SCP. scp would not only use your newly created SSH connection and having fun with it, but it's also secure. Syntax:
scp file.txt remote_username#10.10.0.2:/remote/directory
Step 6: SSH to the server
See Step #4.
Step 7: Navigate to your file's location
Step 8: Ensure that you have the rights to run it
See more here: https://alligator.io/workflow/command-line-basics-file-permissions/
Step 9:: Execute the file
Run
./websocket_daemon.php
If this succeeded, then the job is basically done, you will need some script to run it upon startup and to manage it, but this is not strictly related to the question.
https://oracle-base.com/articles/linux/linux-scripts-running-in-the-background
https://smallbusiness.chron.com/run-command-startup-linux-27796.html
However, if the issue is not resolved yet, read further
Step 10: Ensuring WS support on server
You will need to set up your own WS support. Since you have managed to do so locally on your Windows, hopefully your know-how will work on the remote Linux as well. If not, read more here:
PHP Websocket server in Linux hosting

How to use Supervisor to run Websocket server on AWS Lightsail instance

I'm using this library to add websockets to my codeigniter app. I got everything to work, but I need the websocket server to always run in the background, regardless of the CLI being open or not.
To run the server in the CLI, I run this command:
php index.php welcome index
Which gives me:
Running server on host 0.0.0.0:8282
Authentication activated
Websockets works on my app, but if I close the CLI, the server closes as well. How do I keep this running? I have Supervisor (as suggested for Ratchet), but I have no idea where to go from here. I'm just running a simple PHP server (Ubuntu on AWS Lightsail), not a node one, bytheway.

PHP Web App to run Console SUDO Commands (Deciding how to do it)

My company have a cloud dedicated server, hosted in google cloud, running centos 7 with apache2, php5.5 and mariadb running.
The webserver is running a private application for business clients and companys. Every client has his own database and subdomain, so they, and their own clients can access his applicacion going to http://theirname.example.net/
I've created an interactive command line script for client creation. It creates user and secure password, ftp custom folder, create mysqldatabase and populate it with a sql file, create subdomains and other thing. Also i've made another version of this script with no user interaction, receiving parameters as the client name via command line arguments ( /path-to/script.sh usertocreate mysqluser mysql pass).
So, here is the deal, i want to create a web interface, password protected, just available for my company IP address, this interface should be able to run these SH scripts (not the interactive ones) with sudo permissions.
I was thinking on create a subserver in other port (like http://example.org:2501) using another instance of apache (or other webserver) which runs with a specified user with sudo permissions enables only in the neccesary folders.
Before doing anything, i've created a PHP script which runs commands to console, and tried to run SUDO commands with that. Allowing apache user to sudoers list (just to make it work during develop). I could run these scripts from my web app without SUDO permissions, but they where not working at 100% (since some commands require SUDO). When i try with sudo i receive a code 127 error responde (permission problem).
I stopped there and decided to investigate the best way to do this.
I have full control of the server machine. Apache2 and everything normal is running well. (mariadb, proftpd with passive mode active -100 ports added- )
SELINUX is DISABLED. Firewalld Running
SSH is available for use
I can install another webserver in another port to accomplish this. If a lot of HTTPD configurations should be changed to accomplish this, i will preffer to install another webserver
I can also install any 3rd party software.
I'm a PHP Developer with low experience in other programming languages, if it's necesary to invoke any other programming language to do this (maybe like Python) i would love some docummentation links
Access to this web application would be limited only to my company's static ip address and will be protected
Any thoughts/ideas ? Thanks in advance
PS: If someone want to edit my text and add some colours and format, edition will be aprovved
EDIT TLDR: I want to run another httpd in another with a webapi. This webapi should can run console commands as SUDO. Access to this webserver will be limited to my company's IP. I'm not sure if this is the best way to do it and i want opinions. Also, i'm not pretty sure if its possible to run sudo commands from php without any trouble.

PHP execute command on remote Windows computer with administrator rights

I am currently creating a computer management intranet site using a LAMP web server and PHP running on an Ubuntu server. To remotely shutdown domain connected machines, I usually run a shutdown command in command prompt on my machine, that tells the PCs to shutdown via Active Directory.
Is there a way to connect to a remote Windows machine from Apache on Ubuntu and run the command under an account with domain admin privileges? If possible, I would not like to have a password in plain text in the PHP script, so can this be achieved using public keys or something like that?
http://php.net/manual/en/function.exec.php
Will let you run command line programs that will help you automate this process, it could let you execute a batch file to do what you're looking for

PHP: SSH through an existing SSH connection

I'm looking for a solution to SSH through an existing SSH connection and execute a command with PHP. I've had this working with a simple command. Example:
$result = shell_exec("ssh user#server1 ssh user#server2 ls");
This works when run through CLI but not CGI. I've worked a bit with PHPSecLib but cannot figure out how to open the second connection, once I have a connection to server1.
Anyone have any advice?
When running through CGI, your PHP script probably runs as the web server user, and that user doesn't have access to your SSH keys. Either give the web server user your SSH keys or arrange for the PHP script to run as your user e.g. using suPHP.
And make sure to secure your application so your keys don't get stolen :)
What about $ssh->exec('ssh user#server2 ls')?

Categories