The easiest way for querying all system databases of a server is to assume that databases create by a user come with a database_id >= 5 in sys.databases. But the problem is that distribution databsaes will not be kept into this consideration. Therefore SMO does the following behind the scenes (bioled down to the relevants facts) while querying the objectmodel for the property Server.Database[n].IsSystemObject

SELECT
dtb.name AS [Name],
CAST(case when dtb.name in ('master','model','msdb','tempdb') then 1 else dtb.is_distributor end AS bit) AS [IsSystemObject]
FROM
master.sys.databases AS dtb

-Jens