Showing posts with label app. Show all posts
Showing posts with label app. Show all posts

Wednesday, March 21, 2012

How do I have my app connect to a remote SQL Server that has port 1433 closed?

Hello,
I have a few applications that connect directly to a remote SQL Server,
mainly (but not only) so that web site owners can update the databases
that run their web sites.
The people that maintain the web/SQL server have now said (quite
sensibly) that they want to close port 1433 as it is a security risk. I
would like to know how my client applications are supposed to interact
with the SQL Server if they don't use port 1433. The ISP told me that
this server is the only one they have that has the port open, but they
wouldn't tell me how to do the data access - well, they would, but they
want consultancy rates for it!!
So, anyone any suggestions? The ISP's only suggestion was to have a
private ASP on one of the web sites, that you send the connection
details and SQL, and it returns a recordset as XML. The client
applications could open the recordset from the URL. They did say that
they would put Windows security on the page, so anyone trying to get at
it would need a UID and password, and that the actual URL should be
encoded in the client application so no-one would ever know it exists,
but it still sounds like a major security hole to me. I'm sure there are
better ways of doing this.
I'm sure plenty of people have found a secure way around this, but my
searches haven't turned up anything helpful.
Anyone any suggestions? TIA.
Alan Silver
(anything added below this line is nothing to do with me)I may be missing some details somewhere but here are a few
thoughts/questions:
1. If you are running a web based application, why not make it a real thin
web client and have the relevant connection info/code reside on the web
server that's protected behind your ISP's firewall? That way, clients point
to the web server and interact only with the web server. SQL Server access
is controlled by the web server and is invisible to your clients.
2. Having SQL Server's connection info hidden/encoded in the client
application hoping that nobody will ever know it exists is pretty naive. It
may deter the average user but even script kiddies can figure out ways to
capture the URL information. Just looking at the outgoing stream at the
proxy server or turning on the sniffer will probably do the trick.
Btw, you can configure the default port to talk to from the Client Network
Utility. Just highlight TCP/IP and click on the Properties button.
joe.
"Alan Silver" <alan-silver@.nospam.thanx> wrote in message
news:gRxjBXJ5YuPCFwup@.nospamthankyou.spam...
> Hello,
> I have a few applications that connect directly to a remote SQL Server,
> mainly (but not only) so that web site owners can update the databases
> that run their web sites.
> The people that maintain the web/SQL server have now said (quite sensibly)
> that they want to close port 1433 as it is a security risk. I would like
> to know how my client applications are supposed to interact with the SQL
> Server if they don't use port 1433. The ISP told me that this server is
> the only one they have that has the port open, but they wouldn't tell me
> how to do the data access - well, they would, but they want consultancy
> rates for it!!
> So, anyone any suggestions? The ISP's only suggestion was to have a
> private ASP on one of the web sites, that you send the connection details
> and SQL, and it returns a recordset as XML. The client applications could
> open the recordset from the URL. They did say that they would put Windows
> security on the page, so anyone trying to get at it would need a UID and
> password, and that the actual URL should be encoded in the client
> application so no-one would ever know it exists, but it still sounds like
> a major security hole to me. I'm sure there are better ways of doing this.
> I'm sure plenty of people have found a secure way around this, but my
> searches haven't turned up anything helpful.
> Anyone any suggestions? TIA.
> --
> Alan Silver
> (anything added below this line is nothing to do with me)|||>I may be missing some details somewhere but here are a few
>thoughts/questions:
Thanks, I have commented below...

>1. If you are running a web based application, why not make it a real thin
>web client and have the relevant connection info/code reside on the web
>server that's protected behind your ISP's firewall? That way, clients point
>to the web server and interact only with the web server. SQL Server access
>is controlled by the web server and is invisible to your clients.
I have web sites that run from databases. In order to allow the web site
owners access to modify the databases, I have admin applications that
install on their PCs. At the moment, those applications use a straight
connection to port 1433 on the server.
If I understand you correctly, you are suggesting moving to a web-based
admin. Apart from the amount of work required to rewrite the
applications, this also gives the added problem of extra pages on the
site that I don't want anyone (other than the site owners) to see.

>2. Having SQL Server's connection info hidden/encoded in the client
>application hoping that nobody will ever know it exists is pretty naive. It
>may deter the average user but even script kiddies can figure out ways to
>capture the URL information. Just looking at the outgoing stream at the
>proxy server or turning on the sniffer will probably do the trick.
Yup, that was my thought, which is why I posted the question here
looking for a better answer.
It's worth pointing out that the client app is not freely available, it
is only supplied to customers, so it's not as much of a problem as it
would be in other cases. Not that this removes the worry about people
hacking the app, but it is a slight mitigating factor.
Also, having the info encoded in the client app is no worse than having
port 1433 open. They still have to find a uid and password. At least
with the URL approach I mentioned, they need to figure out the URL, then
figure out the parameters to send, then figure out the values to use,
then find the Windows uid and password for the page. That's a lot more
effort than simply bashing port 1433 with combinations of uid and
password.

>Btw, you can configure the default port to talk to from the Client Network
>Utility. Just highlight TCP/IP and click on the Properties button.
Surely that wouldn't really help. I imagine people looking for ways in
to a server will just probe all ports and see if they get a response.
Changing port wouldn't stop them for many picoseconds ;-)
Thanks for the reply, any further thoughts appreciated.

>"Alan Silver" <alan-silver@.nospam.thanx> wrote in message
>news:gRxjBXJ5YuPCFwup@.nospamthankyou.spam...
>
Alan Silver
(anything added below this line is nothing to do with me)|||Inline
joe.
"Alan Silver" <alan-silver@.nospam.thanx> wrote in message
news:GvcKeYAwtCQCFwwU@.nospamthankyou.spam...
> Thanks, I have commented below...
>
> I have web sites that run from databases. In order to allow the web site
> owners access to modify the databases, I have admin applications that
> install on their PCs. At the moment, those applications use a straight
> connection to port 1433 on the server.
> If I understand you correctly, you are suggesting moving to a web-based
> admin. Apart from the amount of work required to rewrite the applications,
> this also gives the added problem of extra pages on the site that I don't
> want anyone (other than the site owners) to see.
There are 2 different things here. If you have a custom application that is
being used to manage SQL Server, you can have a server component with the
ISP which this "Mangement App" talks to and this can listen on any port that
you want. The app then makes the connection to SQL Server from behind the
firewall. Not a pretty solution since it adds additional steps but it does
give you more control over how you want to layer things out plus it removes
the need to have 1433 exposed.
The same concept can be applied to a web based "management app" where all
the user gets is a very thin layer that hits the web server via some https
connection and issues whatever task instructions it wants (not SQL command).
The web server then makes the connection, again, from behind the firewall to
SQL Server on whichever port you choose. Do still be careful with SQL
Injections here even though the risk is quite a bit lower than sending SQL
across the wire. User responses are still a potential hole.
As far as pages is concerned, they can be "hidden" by filtering userIDs and
presenting only the objects relevant to the userID. You can also provide a
secondary login for administration. The ideas at the conceptual level really
don't change hugely from a rich client though the execution is very
different.

> Yup, that was my thought, which is why I posted the question here looking
> for a better answer.
> It's worth pointing out that the client app is not freely available, it is
> only supplied to customers, so it's not as much of a problem as it would
> be in other cases. Not that this removes the worry about people hacking
> the app, but it is a slight mitigating factor.
> Also, having the info encoded in the client app is no worse than having
> port 1433 open. They still have to find a uid and password. At least with
> the URL approach I mentioned, they need to figure out the URL, then figure
> out the parameters to send, then figure out the values to use, then find
> the Windows uid and password for the page. That's a lot more effort than
> simply bashing port 1433 with combinations of uid and password.
>
> Surely that wouldn't really help. I imagine people looking for ways in to
> a server will just probe all ports and see if they get a response.
> Changing port wouldn't stop them for many picoseconds ;-)
> Thanks for the reply, any further thoughts appreciated.
So you already know putting it in the app doesn't really help. :-)
I'm not in favor of having any SQL being sent across the wire. I'm pretty
wary of SQL Injection risks.

> --
> Alan Silver
> (anything added below this line is nothing to do with me)|||>Inline
Thanks Joe, some useful comments there. My ISP pointed out that they are
moving everything to .NET as the security is much better there. If I'm
going to do any major rewriting, it would probably be better to go that
way.
In the meantime, I might look at using the server component like you
mentioned. I guess this is a sort of DCOM approach, no? Given that my
data access is all modular, I would only have to change one common
module and then recompile all the client apps, so it might not be too
bad.
Thanks again for the comments.
Alan

>joe.
>"Alan Silver" <alan-silver@.nospam.thanx> wrote in message
>news:GvcKeYAwtCQCFwwU@.nospamthankyou.spam...
>There are 2 different things here. If you have a custom application that is
>being used to manage SQL Server, you can have a server component with the
>ISP which this "Mangement App" talks to and this can listen on any port tha
t
>you want. The app then makes the connection to SQL Server from behind the
>firewall. Not a pretty solution since it adds additional steps but it does
>give you more control over how you want to layer things out plus it removes
>the need to have 1433 exposed.
>The same concept can be applied to a web based "management app" where all
>the user gets is a very thin layer that hits the web server via some https
>connection and issues whatever task instructions it wants (not SQL command)
.
>The web server then makes the connection, again, from behind the firewall t
o
>SQL Server on whichever port you choose. Do still be careful with SQL
>Injections here even though the risk is quite a bit lower than sending SQL
>across the wire. User responses are still a potential hole.
>As far as pages is concerned, they can be "hidden" by filtering userIDs and
>presenting only the objects relevant to the userID. You can also provide a
>secondary login for administration. The ideas at the conceptual level reall
y
>don't change hugely from a rich client though the execution is very
>different.
>
>
>So you already know putting it in the app doesn't really help. :-)
>I'm not in favor of having any SQL being sent across the wire. I'm pretty
>wary of SQL Injection risks.
>
>
Alan Silver
(anything added below this line is nothing to do with me)

Monday, March 19, 2012

How do I get Table Owner?

I need to the table owner.
Not from in Enterprise Manager, but from my app. (it's written in Delphi).
Any suggestions?
Thank you,
KeithUSE Northwind
GO

DECLARE @.TABLE_NAME sysname

SELECT @.TABLE_NAME = 'Orders'

SELECT TABLE_SCHEMA
FROM INFORMATION_SCHEMA.Tables
WHERE TABLE_NAME = @.TABLE_NAME|||I'd use:SELECT TABLE_SCHEMA AS owner
FROM INFORMATION_SCHEMA.TABLES
WHERE 'myTable' = TABLE_NAME
-PatP

Monday, March 12, 2012

How do I get a RS report onto an Internet app?

I've written our first Reporting Services report, using SQL Server 2005. Since we've never used RS before, we may, or may not, have done some things correctly. One of the things is that we only have the Reporting Services, and Report Manager, on our SQL Server 2005 server, which is in our network behind our firewall.

We also have an ASP.NET 1.1 application which is used by external users (other businesses that do business with us). Because of the nature of our business, we don't want people from one agency to access data from another agency. Since calling the report in RS involved passing parameters to the report in the URL, I decided that I would hide those details by putting the web page returned by RS into an IFRAME in an aspx page. It works just fine in our network, but I discovered that it does not work at all outside of our network.

So, my question is how do I make the RS report available to users outside of our network, in such a way that they don't have access to the parameters that I pass to the report? Should I discard the whole IFRAME approach? I have been told that it will likely require doing something about passing credentials to the backend server from the ASP.NET app, but I don't know how to do that, nor do I know what would be involved.

Your report will be trying to access data from the SQL Server and your internet site will be passing through port 80 (Open to the world) and therefore the SQL Data side will be blocked, If you open the SQL Port on the firewall then you will see the report runs fine, but then you have a SQL Port open!! Thats a whole other issue, You can do an internal redirect which will give you the same result but slightly more secure.

Your choice on that one...

|||

Andy,

What do you mean by I "... can do an internal redirect...". What is that and how do I do that, please?

|||

Rod, possibly Teo's article will help you: "Harden MS Reporting Services Using Custom Extensions"

Friday, March 9, 2012

How do I find the server name?

I need to deploy a multi-user application to several different customers. My app was built on VB.net and uses SQL Server Express. For remote client to connect to the server I understand that I need to use a connection string something like this:
“Server=ServerName;Database=myDB;Trusted_Connection=True;”

My question is, how will I know what the server name is? Can that be different for different customers? When I test this on my PC, I use (Server=.\SQLEXPRESS;), but what do I use for deployment?

Thanks.

hi,

for each "remote" client, you have to store (on each client) the server instance name they are pointing to...

if I have to connect form my machine to your SQLExpress instance, I should connect to YourMachineName\SQLExpress, as you installed a named instance...

you can perhaps have a look at http://www.sqldev.net/misc.htm for 3 different way to enlist SQL Server instances on the lan...

regards

|||

Thank you Andrea for your response. I would like to make the installation an automated process using InstallShield. I will have two install packages - one for Server and the other for Clients. How can I find the ServerName during the client install?

P.S: I was trying to locate a relevant article/info at the site you mentioned, but could not find any. I would appreciate it if you can point me to a specific article.

|||

hi,

unfortunately, usually you can't...

say you install the "clients" before SQL Server ()... how can you tell what the server name is?

you can perhaps, in your InstallShield code, try instantiating a SQL-DMO.SQLServer object to perform a network scan of installed instances, but this will fail if SQL-DMO has not been already locally installed on the client workstation..

but you can find "smart" solutions.. you can define a share where all your client will point to in order to read some "config" file where they can find the SQL Server they will connect to, but you are there again.. how can you define the network share your app should look for at install time?

so just provide, in your client application, a tool\dialog to define the server name.. at very first startup it could be void and the dialog can automatically pop up, so that the user can finally "browse for installed SQL Server instances" the way you like or is just required to type it's name as the local admin already reported him by internal mail

regards

|||

Thank you for your reply. I have written below what I am thinking as to how I may go about it. Please review and let me know if you have suggestions or comments.

On the install CD, there will be only a Server Install package. During the server installation, it creates a "Client Install" folder and copies Client Install files to that folder. Also it creates a text file called "ServerName.txt" in the same folder and writes the Server's Computer name on it.

To install a client, from the client machine user needs to access the folder on the server and run install. The Client install process reads the Server Computer Name and creates a registry entry on the client.

My application, when run, it reads the "Server's Computer Name" from the registry and coins the connection string and connects to the server.

Please let me know if I can make this process more efficient.

Thanks.

|||

hi,

yes, this can be a "smart" solution...

regards

How do I find out what query someone ran?

Hello All,

We have an app that we do not have the source code for that is behaving badly. I'd like to find out what queries it is running in order to possibly fix the issue form the SQL server side of things. Anyone know what table/view I should select off of to find the queries that have been run recently?

Thanks in advance!

Kenny, your best bet is to fire up SQL Profiler and do some filtering so you only see the queries being executed by the application.

Thanks,
Sam Lester (MSFT)

Friday, February 24, 2012

How do I embed and retrieve Crystal Reports from my app

Using VB .Net 2005 with Crystal Reports XI Release 2. I have a form that has a CrystalReportViewer control on it. When someone prints I run a sub that create a new instance of the form, creates a new reportdocument, loads the report to the new document, then passes the document to the report viewer on the form. This works great except I would like to either embed my crystal reports directly into my app or better yet embed them into thier own reports dll file. I want to do this so updates are easier and I can use the "Publish" function of VB 05 which doesn't seem to like publishing all the seperate files. The embedding should be the easy part, just set them as embedded resource. But I'm having trouble with the syntax to pull them out. For example you can use this to pull out a embdded icon:
Function GetEmbeddedIcon(ByVal strName As String) As Icon
Return New Icon(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(strName))
End Function

But I cannot get the syntax right to pull out and return a crystal report. Anyone have any ideas on how to pull the reports back out or a better way to do this. I dont have a lot of reports, about 15 right now, but that could grow.

-AllanWell...I couldn't find the answer anywhere and no one replied here. But I figured it out so I might as well help someone down the road.

Set your crystal reports to "embedded resource" and the copy to "do not copy". Then in your code you can clal them like any other object with a "New (reportname)". For example I have a crystal reports viewer control (apptly named CrystalReportViewer) on a form called ReportViewerForm. I made a small sub to print reports:

Friend Sub PrintReports(ByVal myReportFileName As ReportDocument, Optional ByVal mySQLFormula As String = "")
' Prints out reports pass to it by other procedures and forms.
Dim PrintPreview As New ReportViewerForm
Try
If mySQLFormula <> "" Then myReportFileName.RecordSelectionFormula = mySQLFormula
PrintPreview.CrystalReportViewer.ReportSource = myReportFileName
PrintPreview.ShowDialog()
Catch ex As CrystalDecisions.CrystalReports.Engine.EngineException
MsgBox("A error was generated by the Crystal Reports engine. Error details: " & ex.Message, MsgBoxStyle.Critical, "Engine Error")
Finally
myReportFileName = Nothing
PrintPreview = Nothing
End Try
End Sub

Then when I need to print a report, for example my Log report (called LogEntryReport.rpt) I call it like this:

PrintReports(New LogEntryReport, "{qLogEntryReport.LogIdNumber} = " & CurrentLogId)

passing my report as a new ReportDocument and my sql command (which is optional for those reports that don't need it). Now I can have one routine that will display reports and call it from anywhere passing the report name. Works dandy and the reports are embedded in the app...less clutter.

Hopefully this helps someone and its not a waste of bandwidth.

-Allan.