How to connect to Windows domain controller using pysmb as user from different domain? - smb

I am able to connect to a W2019 domain controller using python smb modules on Linux using the following type of code:
from smb.SMBConnection import SMBConnection
conn = SMBConnection('administrator', 'p#ssw0rd', 'anything', 'm1')
conn.connect(ip_address)
However, the following doesn't work:
from smb.SMBConnection import SMBConnection
conn = SMBConnection('mydomain\\administrator', 'p#ssw0rd', 'anything', 'm1')
conn.connect(ip_address)
I want to use this interface to connect to a Windows domain controller as a user from a different domain. How can I do that ?
PS1: 'mydomain' is the domain netbios name
PS2: I have also tried passing the 'domain' argument to the constructor. Apparently it is ignored. Authentication succeeds with any value passed in.

Related

Laravel Multi-Tenant Multi-Database Multi-Domain - Problem with default route

I'm studying about multi-tenant with Laravel and I'm having a problem with the routes. The main application works fine, however the main client domain (route / ) returns the 401 error configured in the middleware I created, but the other routes (login, register, etc) work perfectly.
If I put a prefix on the main application routes, then the / client route works normally, but I need the main application not to have a prefix since I want to use it to create the service submission and hiring system.
Anyone who has knowledge on this subject and can take a look at my code and help me find out why only the route is returning this error I will be very grateful.
If i access app.mydefaultapp works
If i access app.myclientapp doesn't works
If i access app.myclientapp/login(or any other route) works
https://pastebin.com/bHHux9sY
I solved the problem by creating a Provider with the same Middleware identification logic, and when accessing the main domain it dynamically loads the routes of the main domain.
$manager = app(ManagerTenant::class);
if ($manager->domainIsMain())
{
$this->registerTenantRoutes();
$this->registerTenantAdminRoutes();
}
https://pastebin.com/20SCsgfL

TWAPI TCL The target principal name is incorrect

I have a file on a server and I am trying to read it.
My code is as follows:
package require http
package require twapi_crypto
http::register https 443 [list ::twapi::tls_socket]
set token [http::geturl "https://$ipaddress/filename"]
set status [http::status $token]
set data [http::data $token]
put $data
and I get the following error:
The target principal name is incorrect
while executing
"InitializeSecurityContext $Credentials $Handle $Target $Inattr 0 $Datarep $inbuflist 0"
(procedure "sspi_step" line 16)
invoked from within
"sspi_step $SpiContext $data"
(procedure "_negotiate2" line 19)
invoked from within
"_negotiate2 $chan"
(procedure "rethrow" line 2)
invoked from within
"rethrow"
invoked from within
"trap {
_negotiate2 $chan
} onerror {} {
variable channels
if {[info exists _channels($chan)]} {
dict set _chan..."
(procedure "_negotiate line 3)
invoked from within
"_negotiate $chan"
(procedure "::twapi::tls::_so_write_andler" line12)
invoked from within
"::twapi::tls::_so_write_handle rc0"
Can somebody redirect me here where the issue is? I get warning from IE when I am trying to access the file and have to click continue even though I have added the certificate to the browser, This is running on a windows machine.
I'm guessing that the subject Common Name on the certificate isn't matching the IP address you're passing in, which is to be expected. You have to use the host name when opening an HTTPS connection.
# Use the right hostname of course
set hostname "securetesting.example.com"
set token [http::geturl "https://$hostname/filename"]
This because that name is used to determine whether the server that you've connected to is the one that you've asked to connect to. Without that, it could be a secure connection to absolutely anyone and that's not a useful kind of security! Yes, this means that you need to spend some time getting DNS right as part of deploying, and yes, this is a bit of a pain. Security usually is.
Interestingly, you should also give the hostname properly even with plain unencrypted HTTP as servers can host multiple sites. The only time you get away with it is when talking unencrypted to a server that only serves up a single site; the web hasn't really worked that way for many years.

Beego must have one register DataBase alias named `default`

In the production server with Beego I get
must have one register DataBase alias named default
I know the db connection credentials work in the server but whenever I do restful request I get this error and the Beego server crashes.
Is there a reason why this is happening?
Below is the code inside main.go init function:
orm.RegisterDriver("postgres", orm.DR_Postgres)
orm.RegisterDataBase("default", "postgres",
fmt.Sprintf("postgres://%s:%s#%s/%s?port=%i",
pgUser, pgPass, pgHost, pgDb, pgPort))
Can you provide a sample of your code?
Based on the error message you have provided, you may not have registered a database with alias default using orm.RegisterDataBase. Here's an example which I have taken from the documentation:
// param 1: Database alias. ORM will use it to switch database.
// param 2: driverName
// param 3: connection string
orm.RegisterDataBase("default", "mysql", "root:root#/orm_test?charset=utf8")
In beego, it is common to register the driver and the database in init of main.go (example).

How to select environment by ip in Laravel

I want laravel to set the environment to "local" when the visitor is from 127.0.0.1, however the Request object is not available yet in bootstrap/start. Is there any built-in way to do this, or am I going to have to directly access $_SERVER['HTTP_CLIENT_IP']?
IP-based environment detection via $app->detectEnvironment() were removed recently. I believe it was in 4.1, because they were not very secure. A user can spoof their IP address and thus potentially access areas of the site you don't want them to access -- or get secure debug information, for example.
I know you asked for an IP solution, but the built-in method for detecting your environment should look like this:
$env = $app->detectEnvironment(array(
'local' => array('MYHOSTNAME'),
));
If you have multiple systems/hostnames working from localhost, just add them to the array. This will keep things much more secure than trying to make IP addresses work.
This sort of thing should work.
$env = $app->detectEnvironment(function() {
if($_SERVER['REMOTE_ADDR'] == '127.0.0.1') { return 'local'; }
});
Swap out REMOTE_ADDR for HTTP_CLIENT_IP if that's how your infrastructure works.
If you want to use the Request object, you might be able to do it in an App::before filter, but I'm not certain if you can change the environment at runtime.

ASP.NET Web API: How do you read server variables in a Web API controller?

How would you read the following server variables in an ASP.NET Web API controller?
HTTP_HOST
SERVER_NAME
REMOTE_HOST / REMOTE_ADDR
I see a System.Net.Http.HttpRequestMessage Request defined, but I don't see a collection containing these variables.
I'm running a website on a single IP with multiple host headers and I need to determine which site they used to get there.
EDIT:
It ended up being something like this:
((System.Web.HttpContextWrapper) Request.Properties["MS_HttpContext"])
.Request.ServerVariables["HTTP_HOST"]
The information you are looking for is dependent on the host you are using and Web API is designed to be host independent. So.... the information you are looking for will be buried in the httpRequestMessage.Properties collection and it will be different depending on your host.
If you move to using the Owin adapter then you will get a standardized Owin environment object.
I was able to all that information from the RequestUri within Request
Request.RequestUri.Scheme + Uri.SchemeDelimiter +
Request.RequestUri.Host + (Request.RequestUri.IsDefaultPort ? string.Empty : (string.Concat(":", Request.RequestUri.Port)))

Resources